Save `plot` for the export module server function
mod_save_plot_to_export_server.Rd
The server side of the shiny module that allows users to save plots generated within the Shiny app and export them to the project on the Seven Bridges Platform.
Usage
mod_save_plot_to_export_server(
id,
plot_reactVals,
output_formats = get_golem_config("PLOT_EXPORT_SUPPORTED_EXT"),
module_title = "Save plot for export",
sbg_directory_path = "/sbgenomics",
btns_div_width = 12
)
Arguments
- id
Module's ID.
- plot_reactVals
A `reactiveValues` variable with a slot `plot` containing an object created with the `recordPlot()` function you would like to save. Please, check out our example app in the inst/demos folder - `plot_exporter_demo_app.R` for a demo on how this module is used.
Example: “`r helper_reactive <- reactiveValues( plot = NULL )# Some observer or eventReactive where you create your plot # and then recordPlot() at the end: plot_output <- eventReactive(input$bins, bins <- input$bins + 1 # Draw the histogram with the specified number of bins faithful[, 2] hist( breaks = seq(min(.), max(.), length.out = bins ), col = "darkgray", border = "white", main = "Geyser eruption duration" ) helper_reactive$plot <- recordPlot() )
output$distPlot <- renderPlot( plot_output() ) “`
- output_formats
The supported output formats. It can be a subset of: "png", "pdf", "svg", "jpeg", "bmp", or "tiff".
- module_title
Title (top left corner) of a modal (popup window) with the settings.
- sbg_directory_path
Path to the mounted `sbgenomics` directory containing `project-files`, `output-files` and `workspace` sub-directories on the instance. These directories are expected to exist on the instance where the app will run. For the purpose of testing your app locally, you can create a mock directory `sbgenomics` with the same structure - containing sub-directories `project-files`, `output-files`, `workspace`, and populate it with test files mimicking the project file structure on the Platform.
- btns_div_width
Width of the `div()` containing the block with the buttons for saving plots in the pop-up modal dialogue. Suitable to update when having one or two buttons out of the supported set. The default value is 12.
Examples
library(shiny)
library(magrittr)
library(sbShinyModules)
# App's UI
ui <- fluidPage(
titlePanel("Save plots for the export to the Platform - Module Demo"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30
)
),
mainPanel(
plotOutput("distPlot"),
fluidRow(
h3("Export Plot to the Platform"),
br(),
sbShinyModules::mod_save_plot_to_export_ui(
id = "plot_exporter"
)
)
)
)
)
# App Server Logic
server <- function(input, output, session) {
# Create reactive values list with the plot field
helper_reactive <- reactiveValues(
plot = NULL
)
plot_output <- eventReactive(input$bins, {
bins <- input$bins + 1
# Draw the histogram with the specified number of bins
faithful[, 2] %>%
hist(
breaks = seq(min(.),
max(.),
length.out = bins
),
col = "darkgray",
border = "white",
main = "Geyser eruption duration"
)
helper_reactive$plot <- recordPlot()
})
output$distPlot <- renderPlot({
plot_output()
})
# Call the plot exporter module
sbShinyModules::mod_save_plot_to_export_server(
id = "plot_exporter",
plot_reactVals = helper_reactive,
module_title = "Save plot to Platform",
sbg_directory_path = system.file("demos/sbgenomics_test",
package = "sbShinyModules"
),
btns_div_width = 12
)
# Note: This way the plot will be saved in a specific directory within the
# package installation path. To find this default location, you can use the
# following R command to determine the installation path of the
# sbShinyModules package:
#
# find.package("sbShinyModules")
#
# Within this directory, exported files will be placed under:
#
# demos/sbgenomics_test/output-files
#
# You can specify your own destination directory for exported files by
# setting the sbg_directory_path parameter in the
# mod_save_plot_to_export_server() function. Ensure that the custom directory
# you choose follows the required organizational structure for proper
# functionality. Refer to the sbg_directory_path parameter description in the
# documentation for detailed requirements.
}
# Run the Shiny app
shinyApp(ui, server)