11

I am setting up a Shiny app that allows the user to download a custom dataset. Following the tutorial, I set up the downloadHandler following the example given in the docs (reproduced here, since the same thing happens if I copy and paste this).

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)

Problem:

This issue only comes up on my Linux* system and seems to work just fine on a Mac. The download and everything works just fine, but the "Save" GUI does not offer me the right file name. There is no error message or warning. Based on my input,

  • I'd expect it to give me data-TIME.csv, i.e. the input to filename. (It does not work either if I give it simple string in that slot).

  • but it offers me DownloadData or whatever name I give to the output variable (cf. screenshot).

enter image description here

Question:

  • Is this a OS issue as I suspect, or am I doing something wrong?

  • How do i fix this? Can I get this to work on any system?

Thanks!

I'm running elementary OS 0.4 Loki, Built on "Ubuntu 16.04.2 LTS", GTK version: 3.18.9. & RStudio 1.0.143

patrick
  • 4,455
  • 6
  • 44
  • 61

1 Answers1

12

If you are using the Rstudio Browser to test you App this could be the problem. I have the same issue on Windows.

When I use the Rstudio Browser the filename is not properly hand over, but if I use Firefox everything works fine. Your code works also fine in my Firefox.

Sagar V
  • 12,158
  • 7
  • 41
  • 68
Alexander Leow
  • 476
  • 2
  • 9
  • 1
    Any idea if this can be fixed for use with RStudio browser? – Oliver Feb 26 '18 at 12:54
  • 1
    I am not sure, but I guess the chance to fix it is not very high. Instead you could force to open Shiny in your default browser and not use the Rstudio browser per default: [See example here](https://stackoverflow.com/questions/35311318/opening-shiny-app-directly-in-the-default-browser) – Alexander Leow Feb 27 '18 at 13:34