R Shiny:用于fileInputs的动态数字的交互式renderTable

时间:2018-01-20 21:43:15

标签: r shiny

我正在尝试创建一个Shiny应用,上传动态数量的CSV文件并通过renderTable显示它们。我使用answer from this link作为动态fileInput。我添加了eventReactive来读取CSV文件,添加了renderUI来获取动态数量tableOutputs。我运行代码时没有收到任何错误,因此我不知道反应性在哪里发生。

服务器:

shinyServer(function(input, output, session) {

  output$fileInputs=renderUI({
    n<-input$nfiles
    html_ui = " "
    for (i in 1:n){

     html_ui <- paste0(html_ui, fileInput(inputId= paste0("fileupload",i), label=paste0("fileupload",i),accept = c("text/csv", "text/comma-separated-values,text/plain",".csv")) )

}
HTML(html_ui)
  })


  Reading <-eventReactive(input$Read, {
    lst<-list()
    n<-input$nfiles
    for (i in 1:n){
      file<-paste0("fileupload",i)
      inFile<-input$file

      if (is.null(inFile))
        return(NULL)
    lst[[i]] <- read.csv(inFile$datapath)

    }
    lst
  })

output$fileoutputs <- renderUI({

  n<-input$nfiles
 for (i in 1:n){

     output[[paste0("table",i)]] <- renderTable( Reading()$lst[[i]] )
     tableOutput(paste0("table",i))
  }

  })

})

UI:

shinyUI(pageWithSidebar(
  headerPanel('Variable files'),
  sidebarPanel(
    numericInput("nfiles", "number of files", value = 2, min = 1, step = 1),
    uiOutput("fileInputs"),
    actionButton("Read", "read")


  ),
  mainPanel(
    uiOutput("fileoutputs")

  )
))

0 个答案:

没有答案
相关问题