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

问题描述

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

提前致谢!我感谢任何和所有反馈!

会话信息

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,verbatimtextoutput("dest"),selectizeInput(inputId = 'destination_city',label = 'Destination Location',choices = us_city_destination,options = list(maxOptions = 10))
           
    ),##commodity CLASS INPUT##
    
    column(4,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")
      )
     )

一个屏幕截图

Error Received

第二个屏幕截图

Console Output

第三个屏幕截图

renderPrint

解决方法

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

private void Spin(){
    if(vl>0)SP.IN(prd,vl,vt,bahan,gr,bbs,bled,0);
    else SP.IN(prd,hl,ht,0);
    Qdot(FCut.fc[0][16]);//<== Only once ^^
}
void Qdot(int fc16){
    String fc=Integer.toString(fc16);
    if(qty<fc16&&mq!=fc16){
        if(qin.getText().length()>0){qin.setText(null);qblk.setText(null);}
    }else{//<==next todo

    }
    if(fc.length()>3){
        switch(fc.length()){
            case 4:fc=fc.charAt(0)+"."+fc.substring(1,3);break;
            case 5:fc=fc.substring(0,2)+"."+fc.substring(2,4);break;
            case 6:fc=fc.substring(0,3)+"."+fc.substring(3,5);break;
            case 7:fc=fc.charAt(0)+"."+fc.substring(1,3)+"."+fc.substring(4,6);break;
            default:fc=fc.substring(0,4)+"."+fc.substring(5,7);
        }
    }
    mqt.setText((R.string.minq+fc));
    Say();
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...