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:
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).