Skip to main content

Pretty Good Hat

Sharing a quick tip that I’ve found useful while building with Shiny, recently: It’s handy to be able to save off the current state of a data set for bringing over to a scratch file. I made the download link appear only when running in my local environment. This way I can easily snapshot my in process data set for experimenting with visualization in my scratch file.

In ui.R:

    if(interactive()) {
      downloadLink("downloadData", "💾️ Download data set") 
    }

And in server.R:

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