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.
If you have questions about this article or would like to discuss ideas presented here, please post on RStudio Community. Our developers monitor these forums and answer questions periodically. See help for more help with all things Shiny.