r - Shiny download file not working -


i creating r shiny application in have dropdown (selectinput) of documents list , download button. functionality users select document list , download doc using download button.

in ui.r

  tabitem(tabname = "downloads",                 selectinput("filenames", "choose document download:",list.files(path="/srv/shiny-server/apps/dsw/files")),   downloadbutton('downloaddata', 'download')), 

in server.r

        datasetinput <- reactive({ switch(input$filenames,input$filenames)    })  output$downloaddata <- downloadhandler( filename = function() {  paste(input$filenames)  }, content = function(file) { write.csv(datasetinput(), file) } ) 

these documents have placed on linux server in www folder of shiny application.

myapp

--app.r --files    -- doc1.doc    -- doc2.csv 

when run application, downloads empty .csv or .docx file not actual file server.

solved follows:

ui.r

 tabitem(tabname = "downloads",             selectinput("filenames", "choose document download:",list.files(path="/srv/shiny-server/apps/files")),  downloadbutton('downloaddata', 'download')) 

server.r

output$downloaddata <- downloadhandler( filename = function() { paste(input$filenames, sep='') }, content = function(file) { myfile <- paste0('/srv/shiny-server/apps/files/',input$filenames, collapse = null)   file.copy(myfile, file) } ) 

Comments