Dynamic Tables R Shiny

Hi,
I've really been struggling to create an app that allows the user to choose a file to display as a table.
(The files are stored on the server and the number of files varies depending on the users input.)
Here is some code that I think is going in the right direction. It creates a given number of tables for just one of the files, but that is because "data/0.tsv" is hardcoded in. What I am getting at is if I have 10 tsv files how could I allow the user to display a given file of their choosing?
Thanks a lot for any help.

library(shiny)
library(DT)
ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("amountTable", "Amount Tables", 1:5)
    ),
    mainPanel(
      # UI output
      uiOutput("dt")
    )
  )
)

server <-  function(input, output) {
    observe({
      lapply(1:input$amountTable, function(num_tbl) {
        output[[paste0('T', num_tbl)]] <- renderTable({
          head(read.table("data/0.tsv", header = FALSE, sep = "\t", col.names = c("Anatomy Term", "Count")))
        })
      })
    })

  output$dt <- renderUI({
    tagList(lapply(1:input$amountTable, function(num) {
      tableOutput(paste0('T', num))
    }))
  })

}

shinyApp(ui, server)

Maybe you can use list.files to get the file names and then a selectInput box to select one?

Thanks for your advice! I have solved my problem using another strategy entirely. Best.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.