0

In the code below, I am just using simple downloadButton() example. It works just fine. But, Why changing the output file name after the "Save File" window pops up, will save the file with no extension (removes the .csv)?

library(shiny)

downloadUI <- function(id){
  ns <- NS(id)
  downloadButton(ns("downloadData"), "Download")
}

downloadServer <- function(id){
  moduleServer(id,
    function(input, output, session){
      # Our dataset
      data <- iris
      
      output$downloadData <- downloadHandler(
        filename = function() {
          paste("data-", Sys.Date(), ".csv", sep="")
        },
        content = function(file) {
          write.csv(data, file)
        }
      )
    }
  )
}

ui <- fluidPage(
  downloadUI("irisDownload")
)

server <- function(input, output, session) {
  downloadServer("irisDownload")
}

shinyApp(ui, server)
  • When you change the file name in the "Save File" menu, are you giving it an extension? What happens at that point is between you and your browser. Shiny doesn't really control that part of the download. It can only suggest the initial name. – MrFlick Jan 27 '23 at 21:58
  • changing the name without extension (because the default name in the "Save File" doesn't have extension either). – Hassan Masoomi Jan 27 '23 at 22:04
  • I just ran your code with no problem. On Download the file name came up as "data-2023-01-27.csv". I changed it to "mydata.csv" and saved it. – stomper Jan 28 '23 at 01:39

0 Answers0