O'Reilly logo

Web Application Development with R Using Shiny by Chris Beeley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Downloading and uploading data

Downloading data is done in a very similar fashion, with the downloadHandler() call looking like the following:

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 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 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required