Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added save multi ggplot module #282

Merged
merged 7 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
export individual plot
pvictor committed Jan 26, 2025
commit 0fc1118c18be4106044e56545b76a17d44eced72
34 changes: 28 additions & 6 deletions dev/save_multi_ggplot.R
Original file line number Diff line number Diff line change
@@ -29,7 +29,10 @@ plot_list_test <- list(
)


card_plot <- function(id, obj) {
card_plot <- function(index,
obj,
export_btn_id = "export",
ns = identity) {
tags$div(
class = "col mb-2",
tags$div(
@@ -50,7 +53,7 @@ card_plot <- function(id, obj) {
class = "card-footer d-flex py-2",
htmltools::tagAppendAttributes(
prettyToggle(
inputId = id,
inputId = ns(paste0("include_plot_", index)),
value = TRUE,
label_on = "Export",
icon_on = icon("check"),
@@ -66,14 +69,19 @@ card_plot <- function(id, obj) {
tags$button(
type = "button",
class = "btn btn-outline-primary",
ph("download")
ph("download"),
onclick = sprintf(
"Shiny.setInputValue('%s', %s, {priority: 'event'})",
ns(export_btn_id), index
)
)
)
)
)
}

save_multi_ggplot_ui <- function(id, file_format = c("png", "pdf", "svg", "jpeg", "pptx")) {
save_multi_ggplot_ui <- function(id,
file_format = c("png", "pdf", "svg", "jpeg", "pptx")) {
ns <- NS(id)
file_format <- match.arg(
arg = file_format,
@@ -153,6 +161,7 @@ save_multi_ggplot_server <- function(id,
function(input, output, session) {

ns <- session$ns
rv <- reactiveValues()

observeEvent(input$select_all, {
plot_list <- plot_list_r()
@@ -175,13 +184,25 @@ save_multi_ggplot_server <- function(id,
X = seq_along(plot_list),
FUN = function(i) {
card_plot(
id = ns(paste0("include_plot_", i)),
obj = plot_list[[i]]
index = i,
obj = plot_list[[i]],
ns = ns,
export_btn_id = "export_plot"
)
}
)
})

# Export individual plots
observeEvent(input$export_plot, {
plot_list <- plot_list_r()
rv$plot <- plot_list[[input$export_plot]]$ggobj
save_ggplot_modal(ns("export_plot"), "Export plot")
})
save_ggplot_server("export_plot", rv)


# Donwload code
output$dl_code <- downloadHandler(
filename = function() {
if (is.reactive(filename_code))
@@ -221,6 +242,7 @@ save_multi_ggplot_server <- function(id,
}
)

# Download multi plots
output$export_png <- download_multi_plot_handler(input, plot_list_r, "png", filename_zip)
output$export_pdf <- download_multi_plot_handler(input, plot_list_r, "pdf", filename_zip)
output$export_svg <- download_multi_plot_handler(input, plot_list_r, "svg", filename_zip)