I want to build a web app that can download excel files. BUT I have a problem when I use the web app: After I click the "Download" button, it shows that the file name is in quotes like the picture I uploaded, and I can't find anything in my documents after I click the "Save" button, whether I delete the quotes or not.
Does anyone have a good suggestion to solve this problem? Thank you for your help.
library(shiny)
library(shinydashboard)
library(XLConnect)
ui <- dashboardPage(
dashboardHeader(title = "excel download"),
dashboardSidebar(downloadLink("downloadData", "Download")),
dashboardBody(),
skin = "purple"
)
server <- function(input, output) {
data1 <- mtcars
output$downloadData <- downloadHandler(
filename = function(){"mtcars.xlsx"},
content = function(file) {
fname <- paste(file,"xlsx",sep=".")
wb <- loadWorkbook(fname,create = TRUE)
createSheet(wb,"cars")
writeWorksheet(wb,data = data1,sheet = "cars")
saveWorkbook(wb)
file.rename(fname,file)
},
contentType="application/xlsx"
)
}
shinyApp(ui = ui, server = server)