Downloading and uploading data

Downloading data is done in a 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 ...

Get Web Application Development with R Using Shiny - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.