Hope that you are all well.
When the user click on the button called "downloadTab", I want to download the table outputs into excel file with multiple sheet. Each sheet is corresponding to a table output.
So,I have 4 data frames (dataTab1,dataTab2,dataTab3,dataTab4) that I want to download as xls file but it doesn't work. Here is my code:
output$downloadTab <- downloadHandler(
filename = function() { paste("tab", " ",Sys.Date(),".xlsx",sep="") },
content = function(file) {
#creation of the workbook
dataxls=createWorkbook(file)
#creation of the sheets
dataTabs1=createSheet(wb=dataxls,sheetName="Compartiments-simulation_sans_changement")
dataTabs2=createSheet(wb=dataxls,sheetName="Esperance-simulation_sans_changement")
dataTabs3=createSheet(wb=dataxls,sheetName="Compartiments-simulation_avec_changement")
dataTabs4=createSheet(wb=dataxls,sheetName="Esperance-simulation_avec_changement")
#add the dataframes to the sheets
addDataFrame(write.xlsx(dataTab1, row.names=F),dataTabs1)
addDataFrame(write.xlsx(dataTab2, row.names=F),dataTabs2)
addDataFrame(write.xlsx(dataTab3, row.names=F),dataTabs3)
addDataFrame(write.xlsx(dataTab4, row.names=F),dataTabs4)
saveWorkbook(dataxls)
write.xlsx(dataxls,file,row.names=F)
}
)