Sasha Sasha - 1 year ago 75
R Question

Storing data uploaded by a user in Shiny app

I am building a Shiny app (R) which allows users to upload their own data (assuming standard file format). The user interface is similar to the example given here. I would like to be able to store that data permanently after user uploads it, so that other users can have access to it as well.

For example, user1 uploads file1.txt and the app allows to analyze this file.
User2 uploads file2.txt. Now any future user of the app will have access to the files uploaded by users 1 and 2 as well as be able to upload more files, which become accessible by other users. Is there a way to do it in Shiny?

Answer Source

You need to copy the uploaded file from the temp directory ($datapath) to a permanent location (i.e. another directory). Then you can use dir() to get a list of user files.

If you need a permanent storage look at

For local storage, see example below.


ui <- shinyUI(fluidPage(

      fileInput('file1', 'Select file to upload' )  
        h4('List of uploaded files:')

server <- shinyServer(function(input, output) {

          if (is.null(input$file1) ) {    return(NULL)  }  
          file.copy(from = input$file1$datapath, to =  paste0('userFile_',input$file1$name )  ) 

        output$fileList <- renderText({  
          dir(pattern = 'userFile_') 

shinyApp(ui, server)