File Upload to select among a list of .csv files stored locally within the shiny folder

shiny

#1

Hi everyone,

I am not new to shiny but definitely very bad at it as you are about to find out. I want to change this example so that the user can only select a .csv from a quite large list of individual .csv files that I have stored locally within the shiny folder ("./data").

(I think) this is easy at least for me if the choice was to be made among the different columns of a single .csv file.

Thank you in advance for your help

     if (interactive()) {

    ui <- fluidPage(
     sidebarLayout(
       sidebarPanel(
         fileInput("file1", "Choose CSV File",
           accept = c(
          "text/csv",
          "text/comma-separated-values,text/plain",
          ".csv")
        ),
      tags$hr(),
      checkboxInput("header", "Header", TRUE)
    ),
    mainPanel(
      tableOutput("contents")
    )
  )
)

server <- function(input, output) {
  output$contents <- renderTable({
    # input$file1 will be NULL initially. After the user selects
    # and uploads a file, it will be a data frame with 'name',
    # 'size', 'type', and 'datapath' columns. The 'datapath'
    # column will contain the local filenames where the data can
    # be found.
    inFile <- input$file1

    if (is.null(inFile))
      return(NULL)

    read.csv(inFile$datapath, header = input$header)
  })
}

shinyApp(ui, server)
}

#2

I don't think you will want to use the fileInput function in this case as the user is not going to be uploading any files.

You can more likely modify this code to get what you want as it has an example of choosing among pre-populated datasets: https://shiny.rstudio.com/articles/validation.html

You will just need to specify where the datasets are (I am still new, but I think they would go in your WWW folder and would then be accessible).


#3

Thanks for your help, I did try selectInput and that is more likely what I need, as you say.

My problem is that I know how to use this for creating a selection among different columns of a dataframe.

However, what I want is to create a selection among different .csv files within the same data folder


#4

I think you have to put the data you want to include in the app in a folder called "Data", and then

df1 <- read.csv("./Data/df1.csv")
df2 <- read.csv("./Data/df2.csv")

And so on... You may find this article useful:


#5

Thanks for your help, your advice has been definetly helpful and sent me on the right path, but still I have not been able to implement it. I have posted a perhaps more reproducible example here with my latest attempt to figure it out:

I will make sure to cross-reference both posts once it is resolved