Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the R Shiny downloadHandler filename to work?

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

like image 746
patrick Avatar asked Jun 11 '17 03:06

patrick


People also ask

How do you enter shiny data?

To add an input in a Shiny app, we need to place an input function *Input() in the ui object. Each input function requires several arguments. The first two are inputId , an id necessary to access the input value, and label which is the text that appears next to the input in the app.

What is shiny package in R?

Shiny is an R package that makes it easy to build interactive web apps straight from R. It helps to host standalone apps on a webpage or embed them in R Markdown documents or build dashboards. One can also extend Shiny apps with CSS themes, htmlwidgets, and JavaScript actions.


1 Answers

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.

like image 50
Alexander Leow Avatar answered Oct 26 '22 15:10

Alexander Leow