Can you exclude certain files from being uploaded to an Shiny App?

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

you could adopt a convention that the file creating program gives different file extensions for files your shiny app should upload vs shouldnt; as shiny::fileInput does have an accept= argument where you can set controls based on file types.

As far as I understand this, the shiny-server actually "sees" the files only once they are uploaded - the upload window is realized via the browser and the file-system.
In the description it only refers to the file type, not the names:
"accept - A character vector of "unique file type specifiers" which gives the browser a hint as to the type of file the server expects. Many browsers use this prevent the user from selecting an invalid file.
A unique file type specifier can be:
-A case insensitive extension like .csv or .rds.
-A valid MIME type, like text/plain or application/pdf
-One of audio/, video/, or image/* meaning any audio, video, or image type, respectively.
"
So no, when it's not possible to follow the above strategy.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.