Help users upload files to your app
Sometimes you’ll want users to be able to upload their own data to your application. Shiny makes it easy to offer your users file uploads straight from the browser, which you can then access from your server logic.
- This feature does not work with Internet Explorer 9 and earlier (not even with Shiny Server).
- By default, Shiny limits file uploads to 5MB per file. You can modify this limit by using the
shiny.maxRequestSizeoption. For example, adding
options(shiny.maxRequestSize = 30*1024^2)to the top of
app.Rwould increase the limit to 30MB.
To run this example, type:
File upload controls are created by using the
fileInput function in your UI. You access the uploaded data similarly to other types of input: by referring to
fileInput function takes a
multiple parameter that can be set to
TRUE to allow the user to select multiple files, and an
accept parameter can be used to give the user clues as to what kind of files the application expects.
This example receives a file and attempts to read it as comma-separated values using
read.csv, then displays the results in a table. As the comment in the
server function indicates,
inFile is either
NULL or a dataframe that contains one row per uploaded file. In this case,
fileInput did not have the
multiple parameter so we can assume there is only one row.
The file contents can be accessed by reading the file named by the
datapath column. See the
?fileInput help topic to learn more about the other columns that are available.
We love it when R users help each other, but RStudio does not monitor or answer the comments in this thread. If you'd like to get specific help, we recommend the RStudio Community as well as the Shiny Discussion Forum for in depth discussion of Shiny related questions and How to get help article for a list of the best ways to get help with R code.comments powered by Disqus