【问题标题】:R Shiny: upload image file and save to serverR Shiny:上传图片文件并保存到服务器
【发布时间】:2016-10-11 11:55:30
【问题描述】:

我正在尝试上传图像,然后使用 Shiny 将其保存到服务器文件系统。

上传我找到了

fileInput

它会创建一个包含图像详细信息和数据路径的 data.frame。那么如何使用它来保存到远程服务器呢?

【问题讨论】:

  • 在 UI 端,当您声明 fileInput('file1', 'Choose CSV File', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')) 之类的内容时,对象 input$file1 将是您在服务器端的文件。您可以从那里使用该文件,将其存储(例如write())或通过 SFTP、云服务或其他方式将其发布到远程服务器。您可能想阅读以下内容:shiny.rstudio.com/articles/persistent-data-storage.html - 这里是上传示例:shiny.rstudio.com/gallery/file-upload.html

标签: r shiny


【解决方案1】:

这是基本示例。它仅将上传的文件复制到服务器上的位置。这是在同一台计算机上,但它可能在任何地方。

library(shiny)

shinyApp(
  ui = shinyUI(  
    fluidRow( 
      fileInput("myFile", "Choose a file", accept = c('image/png', 'image/jpeg'))
    )
  ),
  server = shinyServer(function(input, output,session){
    observeEvent(input$myFile, {
      inFile <- input$myFile
      if (is.null(inFile))
        return()
      file.copy(inFile$datapath, file.path("c:/temp", inFile$name) )
    })
  })
)

shinyApp(ui, server)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    相关资源
    最近更新 更多