0

The download handler is a remarkably popular shiny tool - even for local work. However it is quite annoying when it opens up all the time in the R-Studio directory. Here is the current example program from the Shiny documantion.

library(shiny)

## 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)
}

It opens like this: enter image description here

A few related questions:

  • Is there anyway to override that directory to something more reasonable?
  • Can I specify the default name anywhere (the default is a bit bizarrely take from the name of the output list name).
  • Any insights as to why this is so would be welcome. There seems to be nothing in the docs around this.
Mike Wise
  • 22,131
  • 8
  • 81
  • 104
  • 2
    Since this is browser dependent, would it work to tell the app to open in a different browser? http://stackoverflow.com/questions/35311318/opening-shiny-app-directly-in-the-default-browser – Benjamin Apr 05 '17 at 14:48
  • You mean the default directory is browser dependent? Or the code? I also don't see how that would help. – Mike Wise Apr 05 '17 at 14:53
  • 2
    The default directory is browser dependent. When I open your app in Chrome or IE, it automatically saves to 'C:/Users/myuser/Downloads', which is the default directory listed to those browsers. I'm not sure how the RStudio browser works, but it's default directory is clearly something different. – Benjamin Apr 05 '17 at 14:55
  • Ah - that is a good insight. – Mike Wise Apr 05 '17 at 14:57
  • R-Studio is an Electron app, thus browser based. Might be documented in the Electron docs. – Mike Wise Apr 05 '17 at 14:59
  • and now that I think about it, you could also use `choose.dir` and give the directory you want to start in. How you decide the appropriate starting place is a more complicated question, but for local use you could probably come up with something reasonable. (`getwd`, or some such) – Benjamin Apr 05 '17 at 15:02
  • Not really clear where I would put `choose.dir` in a Shiny program using `downloadHandler` though. Nor would I want to browse twice. – Mike Wise Apr 05 '17 at 15:11

0 Answers0