Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny: upload image file and save to server

Tags:

r

shiny

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?

like image 740
Vlad Avatar asked Dec 19 '22 12:12

Vlad


1 Answers

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)
like image 165
Geovany Avatar answered Jan 03 '23 05:01

Geovany