Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

downloadButton/ downloadHandler does not recognize filename argument

I've run into a problem with downloadHandler() in Shiny:
If I want to download any file via this function, the filename in the download window is the same as the name of the output-variable (in the example: "downloadData"), but not as it is declared in "filename=" in downloadHandler() (which should be "data-2017-02-13.csv").

Note that the following example is from the downloadHandler() - help page, so I guess there is a general problem with R or RStudio in which I write R scripts.
Additionally when I open the shiny app in a web browser, the problem vanishes.
This partially solves it, but I would still like to know why shiny is behaving differently inside RStudio and a web browser.

## Only run examples in interactive R sessions
if (interactive()) {

ui <- fluidPage(
  downloadLink("downloadData", "Download")
)

server <- function(input, output) {
  # Our dataset
  data <- mtcars

  output$downloadData <- downloadHandler(
    filename = function() {
      paste("data-", Sys.Date(), ".csv", sep="")
    },
    content = function(file) {
      write.csv(data, file)
    }
  )
}

shinyApp(ui, server)
}

and here the download window I get: enter image description here

like image 925
Nik3000 Avatar asked Feb 13 '17 15:02

Nik3000


1 Answers

I had the same issue when I used the RStudio preview window and was able to solve this issue by always opening a browser with the command

runApp(launch.browser = TRUE)

like image 98
Stedy Avatar answered Nov 09 '22 06:11

Stedy