earclimate
earclimate

Reputation: 375

shiny: download multiple local files from server

suppose I have generated some(more than one) result files(csv,xls,txt and so on) in a folder(D:\shiny) on the shiny server, How can I download(copy) to the client computer? I means download files rather than data in the session. I have searched from the internet, most of the solutions are read the file and then write to the client, is it possible just copy one by one to local client, and keep file name? or give a download link(the location of files to be download) for download? is the shinyFiles can do such things ?

Upvotes: 0

Views: 2215

Answers (2)

Malanche
Malanche

Reputation: 301

I usually put all the files together in a zip folder that gets created when the user presses a download button:

output$DownloadZip <- downloadHandler(
  filename = function(){
    paste("Results","zip",sep=".")
  },
  content = function(con){
    tmpdir <- tempdir()
    setwd(tempdir())
    filesToSave <- c() #List to hold paths to your files in shiny

    #Put all file paths inside filesToSave...

    zip(zipfile=con, files = filesToSave)
  },
  contentType = "application/zip"
)

You need to install RTools (to zip from command line) for windows 7 and lower.

Upvotes: 3

Wietze314
Wietze314

Reputation: 6020

You could store the result data files on an http accessable folder on the shiny server, and supply a simple download link to that file in your shiny app.

Upvotes: 2

Related Questions