1

I am trying to create a Shiny app that uploads a dynamic number of CSV files and display them through renderTable. I used the answer from this link for the dynamic fileInput. I added an eventReactive to read the CSV files and a renderUI for the dynamic number of tableOutputs. I don't get any errors when I run the code, so I don't know where the reactivity breaks.

Server:

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

  )
))
Jota
  • 17,281
  • 7
  • 63
  • 93
Souha
  • 11
  • 1
  • You can add some log information using print/cat/printf in you code, and therefore see where the reactivity broke. – timat Jan 21 '18 at 09:59
  • I added `output$testingcsv<- renderPrint(Reading())` to test the reactivity in eventReactive. The app returns NULL. I am assuming the dynamic `input$file` is not recognized in the function. – Souha Jan 22 '18 at 15:58
  • one thing is `inFile<-input$file` shoube be `inFile<-input[[file]]` as `file` is a string.. You could also look at this https://stackoverflow.com/questions/35914055/how-to-create-shiny-r-dynamic-rendertable-with-a-number-of-tables-determined-by – timat Jan 23 '18 at 10:27

0 Answers0