Downloading Excel File from XLConnect with R Shiny

后端 未结 1 1528
-上瘾入骨i
-上瘾入骨i 2021-01-31 21:12

Has anyone tried using the download handler in R Shiny to download a freshly created Excel file with XLConnect?

In the ui.R there is the unremarkable line:



        
相关标签:
1条回答
  • 2021-01-31 21:30

    Try using this for the content(...) function; it works for me...

    content = function(file){
          fname <- paste(file,"xlsx",sep=".")
          wb <- loadWorkbook(fname, create = TRUE)
          createSheet(wb, name = "Sheet1")
          writeWorksheet(wb, c(1:3), sheet = "Sheet1") # writes numbers 1:3 in file
          saveWorkbook(wb)
          file.rename(fname,file)
        }
    

    The problem is that file is a randomly generated temp file, without an extension, whereas saveWorkbook(...) requires the .xlsx extension. So this just appends .xlsx to file and uses that for all the XLConnect manipulations, then renames the final file to the original name (e.g., strips off the extension).

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