Download multiple csv files with one button (downloadhandler) with R Shiny

前端 未结 2 1835
Happy的楠姐
Happy的楠姐 2021-01-18 05:40

*Hi, I\'m trying to download multiple csv file from a unique excel file. I want to download (using only one downloadbutton) the differents sheets from the excel file. I don\

相关标签:
2条回答
  • 2021-01-18 05:50

    Hope you've solved this MBnn, but in case anyone else is having similar problems, this case is down to RTools not being installed correctly on windows.

    Currently you need to play close attention while running through the install process, and make sure to hit the checkbox to edit the system path.

    Based on your code, this is likely to be the same issue preventing you from saving XLSX workbooks too.

    0 讨论(0)
  • 2021-01-18 05:56

    As @BigDataScientist pointed out, you could zip all of your csv file and download the zipped file. Your downloadHandler could look like:

    output$download <- downloadHandler(
        filename = function(){
          paste0(input$text,".zip")
    
        },
        content = function(file){
          #go to a temp dir to avoid permission issues
          owd <- setwd(tempdir())
          on.exit(setwd(owd))
          files <- NULL;
    
          #loop through the sheets
          for (i in 1:input$sheet){
            #write each sheet to a csv file, save the name
            fileName <- paste(input$text,"_0",i,".csv",sep = "")
            write.table(data()$wb[i],fileName,sep = ';', row.names = F, col.names = T)
            files <- c(fileName,files)
          }
          #create the zip file
          zip(file,files)
        }
      )
    

    This does not download all the sheets from the excel file but the sheets ranging from 1 to whatever the user has as input in input$sheet.

    You could also disable the download button if the user has not added an excel file/name.

    0 讨论(0)
提交回复
热议问题