Uploading multiple files from shiny app to google drive

Viewed 274

Using the advice from this previous post I was able to figure out how to upload a single file from my shiny app to a specific folder on my google drive. This worked perfectly. Unfortunately, I get the following error when I try to select and upload multiple files though. Any help is appreciated! "Warning in if (!file.exists(media)) { : the condition has length > 1 and only the first element will be used Warning: Error in rationalize_path_name: is_string(name) is not TRUE [No stack trace available]"

Here is minimally reproducible example below

library(googledrive)

ui <- fluidPage(
  fileInput(inputId = "file", 
            label = "Choose file to upload",
            accept = NULL, 
            multiple = TRUE)
)

server <- function(input, output) {

  observeEvent(input$file, {
    drive_upload(media = input$file$datapath,
                 name = input$file$name,
                 path = "my_folder")
  })
}

shinyApp(ui, server)
1 Answers

To upload several files you need to iterate on each input$file$datapath, input$file$name pair:

  observeEvent(input$file, {
    mapply( function(datapath, name){
        drive_upload(media = datapath,
                     name = name,
                     path = "my_folder")},
      input$file$datapath,
      input$file$name)
  })
Related