I have a Shiny app that use a fileInput
to get some files client-side (I cannot use shinyFiles package that manages files server-side).
I want the user to be only able to upload files matching a specific pattern (e.g. helloWorld.txt
) not only matching a file type (e.g. text, csv, etc.).
fileInput
has an accept
argument where you can provide accepted file types. From the doc:
accept A character vector of MIME types; gives the browser a hint of
what kind of files the server is expecting.
I do not just want to specify accepted file types, which is not restrictive enough for my app. Is there a way to do this?
Here is a MWE to accept only text files:
library(shiny)
ui <- fluidPage(
fileInput(
"file_choice",
label = "Choose a files",
multiple = TRUE,
accept = c(
".txt"
)
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
If I use:
accept = c(
"helloWorld.txt"
)
It does not work because it is not a MIME type.
This page Shiny fileInput parameter "accept" issue proposes to handle the selected file afterward server-side, which is what I will end up doing, but I would prefer a restriction a priori and not a posteriori (to avoid the server-side file checking and feedback to user).
shiny
or anything else (even native). Are you sure the capability exists? If you can find a javascript implementation, you should be able to getshiny
to use it (somehow, perhaps throughshinyjs
), but ... the only times I've seen it do that level of filtering/control is when the dialog is app-specific, written for that purpose. – r2evans