Hi everyone,
I am working on a Shiny app where the user uploads a number of csv files based on which some output is generated. The files to be uploaded are created by an external application and are all in the same folder. For the ease of use, I want the user to be able to select all the files in the folder to upload and I am currently using shiny::fileInput()
with the option multiple = TRUE
in the Shiny app.
The problem I have is that the output folder contains some files that can be quite large and that are not needed for the analysis in the app. To save bandwidth and resources, these files should not be uploaded.
Is there any way that I can tell the app which of the selected files should actually be uploaded to the server (based on the filename) and which files should be ignored (i.e. not uploaded)? For example, I only want to upload files that contain the terms control_summary
or cost_summary
in the filename.
I know that you can set a maximum file size in the options (shiny.maxRequestSize
), but this does not seem to solve my problem, as the upload then ends in an error if the large files are selected. What I would like is for the user to still be able to select all files to upload, but only files whose filenames match certain criteria will actually be uploaded.
Here is a minimal example of the app:
library(shiny)
options(shiny.maxRequestSize = 30*1024^2)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# Upload menu is created here:
fileInput(
inputId = "upload",
label = "Upload Files",
buttonLabel = "Select files...",
multiple = TRUE
)
),
mainPanel(
tableOutput(outputId = "files")
)
)
)
server <- function(input, output, session) {
output$files <- renderTable(
input$upload[, c("name", "size")]
)
}
shinyApp(ui, server)
Thanks a lot!
Ian