rshinyshinydashboardarules

Datatable output for Apriori results not displaying in R Shiny App


I'm developing a Shiny app which takes specific city/state inputs and processes these inputs through the Apriori function (arules package). I am running into an issue where I can not get the results to output as a datatable. I have tried various combinations; both utilizing the DT and shiny packages. My current code is below. I know the Apriori function is working because I receive an output in the console when I run the application. (1st screenshot show the app and the error I am receiving, 2nd screenshot show the output from the console, 3rd screenshot shows that by using renderPrint I receive a text output (not listed below in Server or UI code).

Thanks in advance! I appreciate any and all feedback!

Session Info

R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1

locale:
[1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     
LC_MONETARY=C.UTF-8   
[6] LC_MESSAGES=C.UTF-8    LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           
LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] maps_3.3.0           gmapsdistance_3.4    RPostgres_1.3.3      arulesViz_1.5-0      
arules_1.6-8         Matrix_1.3-4        
[7] googleway_2.7.3      plotly_4.9.4.1       forcats_0.5.1        stringr_1.4.0        
dplyr_1.0.7          purrr_0.3.4         
[13] readr_2.0.0          tidyr_1.1.3          tibble_3.1.3         ggplot2_3.3.5        
tidyverse_1.3.1      RPostgreSQL_0.6-2   
[19] DBI_1.1.1            shinydashboard_0.7.1 shiny_1.6.0         

loaded via a namespace (and not attached):
[1] bitops_1.0-7      fs_1.5.0          lubridate_1.7.10  bit64_4.0.5       httr_1.4.2        
tools_4.1.0       backports_1.2.1  
[8] bslib_0.2.5.1     utf8_1.2.1        R6_2.5.0          DT_0.18           lazyeval_0.2.2    
colorspace_2.0-2  withr_2.4.2      
[15] tidyselect_1.1.1  bit_4.0.4         curl_4.3.2        compiler_4.1.0    cli_3.0.1         
rvest_1.0.0       xml2_1.3.2       
[22] sass_0.4.0        scales_1.1.1      digest_0.6.27     rmarkdown_2.9     pkgconfig_2.0.3   
htmltools_0.5.1.1 sourcetools_0.1.7
[29] dbplyr_2.1.1      fastmap_1.1.0     htmlwidgets_1.5.3 rlang_0.4.11      readxl_1.3.1      
rstudioapi_0.13   jquerylib_0.1.4  
[36] generics_0.1.0    jsonlite_1.7.2    crosstalk_1.1.1   RCurl_1.98-1.3    magrittr_2.0.1    
Rcpp_1.0.7        munsell_0.5.0    
[43] fansi_0.5.0       lifecycle_1.0.0   stringi_1.7.3     yaml_2.2.1        grid_4.1.0        
blob_1.2.2        promises_1.2.0.1 
[50] crayon_1.4.1      lattice_0.20-44   haven_2.4.1       hms_1.1.0         knitr_1.33        
pillar_1.6.1      XML_3.99-0.6     
[57] reprex_2.0.0      glue_1.4.2        evaluate_0.14     data.table_1.14.0 modelr_0.1.8      
vctrs_0.3.8       tzdb_0.1.2       
[64] httpuv_1.6.1      cellranger_1.1.0  gtable_0.3.0      assertthat_0.2.1  cachem_1.0.5      
xfun_0.24         mime_0.11        
[71] xtable_1.8-4      broom_0.7.8       later_1.2.0       viridisLite_0.4.0 ellipsis_0.3.2

Summarized Server Side

server <- function(input,output, session) {   

## Apriori Function ##

 apriori_react_rhs <- eventReactive(input$go,{

                                     
    inspect(apriori(lane_basket,
        parameter = list(
        support = 0.05,
        confidence = 0.75,
        minlen = 2),
        appearance = (list(lhs = as.character(paste0(input$com,
        ",",input$origin_city,",",input$destination_city))))))
  })

output$apriori_table_2 <- DT::renderDataTable(DT::datatable(DATAFRAME(
apriori_react_rhs())))

}

Summarized UI Side

shinyUI(
   dashboardPage(

    ##ORIGIN LOCATION INPUT##
    
    column(4,
           hr(),
           verbatimTextOutput("orig"),
           selectizeInput(inputId = 'origin_city', label = 'Origin Location', choices = us_city_origin, multiple = FALSE, options = list(maxOptions = 10))
    ),
    
    ##DESTINATION LOCATION INPUT##
    
    column(4,
           hr(),
           verbatimTextOutput("dest"),
           selectizeInput(inputId = 'destination_city', label = 'Destination Location', choices = us_city_destination, multiple = FALSE, options = list(maxOptions = 10))
           
    ),
    
    ##COMMODITY CLASS INPUT##
    
    column(4,
           hr(),
           verbatimTextOutput("com"),
           selectizeInput(inputId = 'com', label = 'Commodity Class', choices = commodity, multiple = FALSE),
           
           
           actionButton("go", "Apply Changes"))
           
           ),
 
   h2("Table output"),
  fluidRow(
 
  ##DATA TABLE OUTPUT##

    DT::dataTableOutput("apriori_table_2")
      )
     )

1st Screenshot

Error Received

2nd Screenshot

Console Output

3rd Screenshot

renderPrint


Solution

  • I was able to figure out the issue by changing the server side script to read (for whatever reason the DT is visible when I run the App in Rstudio but not visible once published in shiny server):

     output$apriori_table_rhs <- DT::renderDataTable({DT::datatable(as.data.frame(apriori_react_rhs()))},server = TRUE)