Appsilon/shiny.react

Add a `startDownload` helper

kamilzyla opened this issue · 0 comments

Problem

Currently, there is no straightforward way to trigger downloads from React. In effect, e.g. a PrimaryButton from shiny.fluent cannot be easily used as a download button (but see Appsilon/shiny.fluent#39 for a workaround).

Solution

It should be possible to create a startDownload() helper, which could be used the following way:

shinyApp(
  ui = PrimaryButton(onClick = startDownload("file"), text = "Download"),
  server = function(input, output) {
    output$file <- downloadHandler(
      filename = function() "iris.csv",
      content = function(file) write.csv(iris, file)
    )
  }
)