Apriori 结果的数据表输出未显示在 R Shiny App 中

Datatable output for Apriori results not displaying in R Shiny App

我正在开发一个闪亮的应用程序,它接受特定的 city/state 输入并通过 Apriori 函数(arules 包)处理这些输入。我正在 运行 遇到无法将结果输出为数据表的问题。我尝试过各种组合;都使用 DTshiny 包。我当前的代码如下。我知道 Apriori 函数正在运行,因为当我 运行 应用程序时,我在控制台中收到了一个输出。 (第一个屏幕截图显示了应用程序和我收到的错误,第二个屏幕截图显示了控制台的输出,第三个屏幕截图显示通过使用 renderPrint 我收到了一个文本输出(未在下面的服务器或 UI 中列出代码)。

提前致谢!感谢所有反馈!

Session 信息

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

汇总服务器端

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())))

}

总结UI边

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")
      )
     )

第一个截图

第二张截图

第三张截图

我能够通过将服务器端脚本更改为读取来解决问题(无论出于何种原因,当我 运行 Rstudio 中的应用程序时 DT 是可见的,但在闪亮的服务器中发布后不可见):

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