Vlad
Vlad

Reputation: 3764

Upload image file and save to server

I'm trying to upload an image and then save it to the server file system using Shiny.

To upload I've found

fileInput

which creates a data.frame containing the image details and datapath. How then can this be used to save to a remote server?

Upvotes: 8

Views: 9379

Answers (1)

Geovany
Geovany

Reputation: 5677

Here is basic example. It only copy the uploaded file to at location on server. In this is in the same computer, but it could be anywhere.

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)

Upvotes: 14

Related Questions