'File copy with downloadhandler in ShinyApp

I would like to be able to make a file.copy through the dowloadhandler so that the user can choose the directory where they want to put the copy. I tried to do it as shown below but it doesn't work. I would appreciate any help or suggestion.


library(shiny)

ui <- fluidPage(
  downloadButton("download.data", "Download")
)

server <- function(input, output, session) {
  
  # there is where the file is located
  dir <- "documents/file.pdf" # can be a .xslx, csv, etc
  
  output$download.data <- downloadHandler(
       filename <- function() {
         "fileName"
       },
       
       content <- function(file) {
         file.copy(dir, file)
       }
     )
  
}

shinyApp(ui, server)


Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source