【问题标题】:Storing data uploaded by a user in Shiny app在 Shiny 应用中存储用户上传的数据
【发布时间】:2016-12-27 15:13:29
【问题描述】:

我正在构建一个 Shiny 应用程序 (R),它允许用户上传自己的数据(假设标准文件格式)。用户界面类似于给出的示例here。我希望能够在用户上传数据后永久存储该数据,以便其他用户也可以访问它。

例如,user1 上传 file1.txt,应用程序允许分析此文件。 User2 上传 file2.txt。现在,该应用程序的任何未来用户都可以访问用户 1 和 2 上传的文件,并且能够上传更多文件,这些文件可供其他用户访问。有没有办法在 Shiny 中做到这一点?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您需要将上传的文件从临时目录 ($datapath) 复制到永久位置(即另一个目录)。然后您可以使用 dir() 获取用户文件列表。

    如果您需要永久存储,请查看http://deanattali.com/blog/shiny-persistent-data-storage/

    对于本地存储,请参见下面的示例。

    library(shiny) 
    
    ui <- shinyUI(fluidPage(
    
      sidebarLayout(
        sidebarPanel(
          fileInput('file1', 'Select file to upload' )  
        ),
        mainPanel(
            h4('List of uploaded files:')
           ,verbatimTextOutput('fileList')
        )
      ))
    )
    
    server <- shinyServer(function(input, output) {
    
            observe({  
              if (is.null(input$file1) ) {    return(NULL)  }  
              file.copy(from = input$file1$datapath, to =  paste0('userFile_',input$file1$name )  ) 
            }) 
    
            output$fileList <- renderText({  
              input$file1
              dir(pattern = 'userFile_') 
            })
    })
    
    shinyApp(ui, server)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2023-03-24
    • 2011-06-02
    • 1970-01-01
    • 2014-12-27
    相关资源
    最近更新 更多