Downloading and uploading data
Downloading data is done in a very similar fashion, which looks like the following downloadHandler()
call:
output$downloadData <- downloadHandler( filename = function(){ "myData.csv" } content = function(file){ write.csv(passData(), file) } )
Uploading data is achieved using the fileInput()
function. In the following example, we will assume that the user wishes to upload a comma-separated spreadsheet (.csv
) file. The button is added to ui.R
in the following manner:
fileInput("uploadFile", "Upload your own CSV file")
This button allows a user to select their own .csv
file, and it also makes a variety of objects based on the ID (in this case, input$uploadFile$...
) available from server.R
. The most useful is input$uploadFile$datapath
, which is a path to the file itself and can be turned into a dataframe using read.csv()
:
userData <- read.csv(input$uploadFile$datapath)
There are other bits of information about the...