Collects the plot object, its underlying data, statistical testing details (if applied), and optional UI input values into a single list for downstream download generation.
Arguments
- plot_reactive
A reactive expression returning a
plotlyplot object.- stats_reactive
Optional. A reactive expression (e.g. a
shiny::reactiveVal()) returning adata.frameof statistical test results. WhenNULLor when the reactive returnsNULL, no statistics data is included.- inputs_reactive
Optional. A reactive expression returning a named list of UI input values. When
NULLor when it returnsNULL, no UI input data is included.
Value
A named list with elements:
- plot
The
plotlyplot object.- plot_data
A
data.frameof the plot's underlying data.- stats
A
data.frameof statistical test results, orNULL.- inputs
A
data.frameof UI input names and values, orNULL.
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)
} # }