Create download handler for plot with source data
Source:R/plot_source_data.R
create_source_download_handler.RdGenerates a Shiny downloadHandler() that bundles the interactive plot and
its supporting data into a single .zip archive.
Arguments
- data_list
A reactive returning either a single summary list produced by
collect_source_data()(with elementsplot,plot_data,stats, andinputs), or a named list of such summaries (one per plot). When a named list of summaries is supplied, each summary is written to its own set of files (prefixed with the list name) so several plots can be bundled into a single archive.- filename_base
character(1). Base name for the downloaded.zipfile without extension. The final filename takes the form<filename_base>_<Sys.Date()>.zip.
Examples
if (FALSE) { # \dontrun{
# Example usage in a Shiny app
library(shiny)
library(plotly)
library(VizModules)
ui <- fluidPage(
plotlyOutput("my_plot"),
downloadButton("download_data", "Download Plot and Data")
)
server <- function(input, output) {
plot_reactive <- reactive({
plot_ly(mtcars, x = ~mpg, y = ~hp, type = "scatter", mode = "markers")
})
data_list <- collect_source_data(plot_reactive)
output$my_plot <- renderPlotly(plot_reactive())
output$download_data <- create_source_download_handler(reactive(data_list))
}
shinyApp(ui, server)
} # }