diff --git a/DESCRIPTION b/DESCRIPTION index 34944923..6b5167b7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ Depends: osprey (>= 0.1.17), R (>= 3.6), shiny (>= 1.8.1), - teal (>= 1.0.0), + teal (>= 1.0.0.9003), teal.transform (>= 0.7.0) Imports: bslib (>= 0.8.0), @@ -37,7 +37,7 @@ Imports: teal.code (>= 0.7.0), teal.data (>= 0.8.0), teal.logger (>= 0.4.0), - teal.reporter (>= 0.5.0), + teal.reporter (>= 0.5.0.9001), teal.widgets (>= 0.5.0), tern (>= 0.9.7), tidyr (>= 0.8.3) @@ -49,7 +49,9 @@ Suggests: testthat (>= 3.2.3), withr (>= 3.0.0) Remotes: - insightsengineering/osprey + insightsengineering/osprey, + insightsengineering/teal, + insightsengineering/teal.reporter Config/Needs/verdepcheck: insightsengineering/osprey, rstudio/shiny, insightsengineering/teal, insightsengineering/teal.slice, insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr, @@ -65,4 +67,4 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 +RoxygenNote: 7.3.3 diff --git a/R/tm_g_ae_oview.R b/R/tm_g_ae_oview.R index 53b896d0..cde73e55 100644 --- a/R/tm_g_ae_oview.R +++ b/R/tm_g_ae_oview.R @@ -12,6 +12,7 @@ #' sub-groups (e.g. Serious events, Related events, etc.) #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -129,10 +130,6 @@ ui_g_ae_oview <- function(id, ...) { plot_decorate_output(id = ns(NULL)) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### teal.widgets::optionalSelectInput( ns("arm_var"), "Arm Variable", @@ -198,14 +195,10 @@ ui_g_ae_oview <- function(id, ...) { srv_g_ae_oview <- function(id, data, - filter_panel_api, - reporter, dataname, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(isolate(data()), "teal_data") @@ -286,7 +279,16 @@ srv_g_ae_oview <- function(id, output_q <- shiny::debounce( millis = 200, r = reactive({ - ANL <- data()[[dataname]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# AE Overview"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + + ANL <- obj[[dataname]] teal::validate_has_data(ANL, min_nrow = 10, msg = sprintf("%s has not enough data", dataname)) @@ -297,7 +299,7 @@ srv_g_ae_oview <- function(id, "Treatment or Control not found in Arm Variable. Perhaps they have been filtered out?" )) - q1 <- teal.code::eval_code(data(), "library(dplyr)") %>% + q1 <- obj %>% teal.code::eval_code( code = as.expression(c( bquote(anl_labels <- formatters::var_labels(.(as.name(dataname)), fill = FALSE)), @@ -309,6 +311,8 @@ srv_g_ae_oview <- function(id, )) ) + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + teal.code::eval_code( q1, code = as.expression(c( @@ -339,25 +343,6 @@ srv_g_ae_oview <- function(id, verbatim_content = reactive(teal.code::get_code(output_q())), title = paste("R code for", label) ) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "AE Overview", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_ae_sub.R b/R/tm_g_ae_sub.R index 4b624965..2071f1dd 100644 --- a/R/tm_g_ae_sub.R +++ b/R/tm_g_ae_sub.R @@ -13,6 +13,7 @@ #' @author Molly He (hey59) \email{hey59@gene.com} #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -104,10 +105,6 @@ ui_g_ae_sub <- function(id, ...) { plot_decorate_output(id = ns(NULL)) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), helpText("Analysis data:", tags$code("ADAE")), teal.widgets::optionalSelectInput( @@ -175,14 +172,10 @@ ui_g_ae_sub <- function(id, ...) { srv_g_ae_sub <- function(id, data, - filter_panel_api, - reporter, dataname, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -317,8 +310,16 @@ srv_g_ae_sub <- function(id, output_q <- shiny::debounce( millis = 200, r = reactive({ - ANL <- data()[[dataname]] - ADSL <- data()[["ADSL"]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# AE by Subgroups"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + + ANL <- obj[[dataname]] + ADSL <- obj[["ADSL"]] teal::validate_has_data(ANL, min_nrow = 10, msg = sprintf("%s has not enough data", dataname)) @@ -347,29 +348,33 @@ srv_g_ae_sub <- function(id, bquote(group_labels <- setNames(.(group_labels), .(input$groups))) } - teal.code::eval_code(data(), code = group_labels_call) %>% - teal.code::eval_code(code = "") %>% - teal.code::eval_code( - code = as.expression(c( - bquote( - plot <- osprey::g_ae_sub( - id = .(as.name(dataname))$USUBJID, - arm = as.factor(.(as.name(dataname))[[.(input$arm_var)]]), - arm_sl = as.character(ADSL[[.(input$arm_var)]]), - trt = .(input$arm_trt), - ref = .(input$arm_ref), - subgroups = .(as.name(dataname))[.(input$groups)], - subgroups_sl = ADSL[.(input$groups)], - subgroups_levels = group_labels, - conf_level = .(input$conf_level), - diff_ci_method = .(input$ci), - fontsize = .(font_size()), - arm_n = .(input$arm_n), - draw = TRUE - ) + q1 <- teal.code::eval_code(obj, code = group_labels_call) %>% + teal.code::eval_code(code = "") + + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + + teal.code::eval_code( + q1, + code = as.expression(c( + bquote( + plot <- osprey::g_ae_sub( + id = .(as.name(dataname))$USUBJID, + arm = as.factor(.(as.name(dataname))[[.(input$arm_var)]]), + arm_sl = as.character(ADSL[[.(input$arm_var)]]), + trt = .(input$arm_trt), + ref = .(input$arm_ref), + subgroups = .(as.name(dataname))[.(input$groups)], + subgroups_sl = ADSL[.(input$groups)], + subgroups_levels = group_labels, + conf_level = .(input$conf_level), + diff_ci_method = .(input$ci), + fontsize = .(font_size()), + arm_n = .(input$arm_n), + draw = TRUE ) - )) - ) + ) + )) + ) }) ) @@ -380,26 +385,6 @@ srv_g_ae_sub <- function(id, verbatim_content = reactive(teal.code::get_code(output_q())), title = paste("R code for", label), ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "AE Subgroups", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_butterfly.R b/R/tm_g_butterfly.R index efc5b0dc..358e8cd0 100644 --- a/R/tm_g_butterfly.R +++ b/R/tm_g_butterfly.R @@ -33,6 +33,7 @@ #' used directly as filter. #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -166,10 +167,6 @@ ui_g_butterfly <- function(id, ...) { teal.widgets::plot_with_settings_ui(id = ns("butterflyplot")) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), helpText("Dataset is:", tags$code(a$dataname)), if (!is.null(a$filter_var)) { @@ -264,9 +261,7 @@ ui_g_butterfly <- function(id, ...) { ) } -srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") +srv_g_butterfly <- function(id, data, dataname, label, plot_height, plot_width) { checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -386,8 +381,17 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe output_q <- shiny::debounce( millis = 200, r = reactive({ - ADSL <- data()[["ADSL"]] - ANL <- data()[[dataname]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Butterfly Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + + ADSL <- obj[["ADSL"]] + ANL <- obj[[dataname]] teal::validate_has_data(ADSL, min_nrow = 0, msg = sprintf("%s Data is empty", "ADSL")) teal::validate_has_data(ANL, min_nrow = 0, msg = sprintf("%s Data is empty", dataname)) @@ -422,13 +426,13 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe adsl_vars <- unique(c("USUBJID", "STUDYID", varlist_from_adsl)) anl_vars <- unique(c("USUBJID", "STUDYID", varlist_from_anl)) - q1 <- teal.code::eval_code(data(), "library(dplyr)") %>% - teal.code::eval_code( - code = bquote({ - ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() - ANL <- .(as.name(dataname))[, .(anl_vars)] %>% as.data.frame() - }) - ) + q1 <- teal.code::eval_code( + obj, + code = bquote({ + ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() + ANL <- .(as.name(dataname))[, .(anl_vars)] %>% as.data.frame() + }) + ) if (!("NULL" %in% filter_var) && !is.null(filter_var)) { q1 <- teal.code::eval_code( @@ -461,6 +465,24 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe ) } + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + + if (!is.null(input$filter_var) || !is.null(input$facet_var) || !is.null(input$sort_by_var)) { + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "### Selected Options") + } + if (!is.null(input$filter_var)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Preset Data Filters: ", paste(input$filter_var, collapse = ", "), ".")) + } + if (!is.null(input$facet_var)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Faceted by: ", paste(input$facet_var, collapse = ", "), ".")) + } + if (!is.null(input$sort_by_var)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Sorted by: ", paste(input$sort_by_var, collapse = ", "), ".")) + } + if (!is.null(right_val) && !is.null(left_val)) { q1 <- teal.code::eval_code( q1, @@ -492,7 +514,7 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe ) } - teal.code::eval_code(q1, quote(plot)) + q1 }) ) @@ -511,38 +533,6 @@ srv_g_butterfly <- function(id, data, filter_panel_api, reporter, dataname, labe title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Butterfly Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - if (!is.null(input$filter_var) || !is.null(input$facet_var) || !is.null(input$sort_by_var)) { - card$append_text("Selected Options", "header3") - } - if (!is.null(input$filter_var)) { - card$append_text(paste0("Preset Data Filters: ", paste(input$filter_var, collapse = ", "), ".")) - } - if (!is.null(input$facet_var)) { - card$append_text(paste0("Faceted by: ", paste(input$facet_var, collapse = ", "), ".")) - } - if (!is.null(input$sort_by_var)) { - card$append_text(paste0("Sorted by: ", paste(input$sort_by_var, collapse = ", "), ".")) - } - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_events_term_id.R b/R/tm_g_events_term_id.R index a0af565d..9cbb36c2 100644 --- a/R/tm_g_events_term_id.R +++ b/R/tm_g_events_term_id.R @@ -11,6 +11,7 @@ #' and pre-selected option names that can be used to specify the term for events #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -104,10 +105,6 @@ ui_g_events_term_id <- function(id, ...) { plot_decorate_output(id = ns(NULL)) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### teal.widgets::optionalSelectInput( ns("term"), "Term Variable", @@ -202,14 +199,10 @@ ui_g_events_term_id <- function(id, ...) { srv_g_events_term_id <- function(id, data, - filter_panel_api, - reporter, dataname, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -304,7 +297,15 @@ srv_g_events_term_id <- function(id, ) output_q <- reactive({ - ANL <- data()[[dataname]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Events by Term"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + + ANL <- obj[[dataname]] teal::validate_inputs(iv()) @@ -320,7 +321,7 @@ srv_g_events_term_id <- function(id, anl_vars <- c("USUBJID", "STUDYID", input$term) q1 <- teal.code::eval_code( - data(), + obj, code = bquote( ANL <- merge( x = ADSL[, .(adsl_vars), drop = FALSE], @@ -337,6 +338,8 @@ srv_g_events_term_id <- function(id, msg = "Analysis data set must have at least 10 data points" ) + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + q2 <- teal.code::eval_code( q1, code = bquote( @@ -368,26 +371,6 @@ srv_g_events_term_id <- function(id, title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Events by Term", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_heat_bygrade.R b/R/tm_g_heat_bygrade.R index cfeee251..8b3347c3 100644 --- a/R/tm_g_heat_bygrade.R +++ b/R/tm_g_heat_bygrade.R @@ -30,6 +30,7 @@ #' specify to `NA` if no concomitant medications data is available #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -195,10 +196,6 @@ ui_g_heatmap_bygrade <- function(id, ...) { plot_decorate_output(id = ns(NULL)) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### teal.widgets::optionalSelectInput( ns("id_var"), "ID Variable", @@ -277,8 +274,6 @@ ui_g_heatmap_bygrade <- function(id, ...) { srv_g_heatmap_bygrade <- function(id, data, - filter_panel_api, - reporter, sl_dataname, ex_dataname, ae_dataname, @@ -286,8 +281,6 @@ srv_g_heatmap_bygrade <- function(id, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") if (!is.na(sl_dataname)) checkmate::assert_names(sl_dataname, subset.of = names(data)) @@ -397,10 +390,19 @@ srv_g_heatmap_bygrade <- function(id, output_q <- shiny::debounce( millis = 200, r = reactive({ - ADSL <- data()[[sl_dataname]] - ADEX <- data()[[ex_dataname]] - ADAE <- data()[[ae_dataname]] - ADCM <- data()[[cm_dataname]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Heatmap by Grade"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + + ADSL <- obj[[sl_dataname]] + ADEX <- obj[[ex_dataname]] + ADAE <- obj[[ae_dataname]] + ADCM <- obj[[cm_dataname]] teal::validate_has_data(ADSL, min_nrow = 1, msg = sprintf("%s contains no data", sl_dataname)) teal::validate_inputs(iv(), iv_cm()) @@ -408,7 +410,7 @@ srv_g_heatmap_bygrade <- function(id, shiny::validate(shiny::need(all(input$conmed_level %in% ADCM[[input$conmed_var]]), "Updating Conmed Levels")) } - qenv <- teal.code::eval_code(data(), "library(dplyr)") + qenv <- obj if (isTRUE(input$plot_cm)) { ADCM <- qenv[[cm_dataname]] @@ -433,7 +435,9 @@ srv_g_heatmap_bygrade <- function(id, ) } - qenv <- teal.code::eval_code( + teal.reporter::teal_card(qenv) <- c(teal.reporter::teal_card(qenv), "## Plot") + + teal.code::eval_code( qenv, code = bquote( plot <- osprey::g_heat_bygrade( @@ -451,7 +455,6 @@ srv_g_heatmap_bygrade <- function(id, ) ) ) - teal.code::eval_code(qenv, quote(plot)) }) ) @@ -462,26 +465,6 @@ srv_g_heatmap_bygrade <- function(id, title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Heatmap by Grade", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_patient_profile.R b/R/tm_g_patient_profile.R index 041394c4..12c477ad 100644 --- a/R/tm_g_patient_profile.R +++ b/R/tm_g_patient_profile.R @@ -47,6 +47,7 @@ #' @template author_qit3 #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @details #' As the patient profile module plots different domains in one plot, the study day (x-axis) @@ -220,10 +221,6 @@ ui_g_patient_profile <- function(id, ...) { teal.widgets::plot_with_settings_ui(id = ns("patientprofileplot")) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), selectizeInput( inputId = ns("patient_id"), @@ -341,8 +338,6 @@ ui_g_patient_profile <- function(id, ...) { srv_g_patient_profile <- function(id, data, - filter_panel_api, - reporter, patient_id, sl_dataname, ex_dataname, @@ -354,8 +349,6 @@ srv_g_patient_profile <- function(id, ae_line_col_opt, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelApi") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") if (!is.na(ex_dataname)) checkmate::assert_names(ex_dataname, subset.of = names(data)) @@ -461,6 +454,15 @@ srv_g_patient_profile <- function(id, output_q <- shiny::debounce( millis = 200, r = reactive({ + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Patient Profile"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + teal::validate_inputs(iv()) # get inputs --- @@ -507,31 +509,31 @@ srv_g_patient_profile <- function(id, )) # get ADSL dataset --- - ADSL <- data()[[sl_dataname]] + ADSL <- obj[[sl_dataname]] ADEX <- NULL if (isTRUE(select_plot()[ex_dataname])) { - ADEX <- data()[[ex_dataname]] + ADEX <- obj[[ex_dataname]] teal::validate_has_variable(ADEX, adex_vars) } ADAE <- NULL if (isTRUE(select_plot()[ae_dataname])) { - ADAE <- data()[[ae_dataname]] + ADAE <- obj[[ae_dataname]] teal::validate_has_variable(ADAE, adae_vars) } ADRS <- NULL if (isTRUE(select_plot()[rs_dataname])) { - ADRS <- data()[[rs_dataname]] + ADRS <- obj[[rs_dataname]] teal::validate_has_variable(ADRS, adrs_vars) } ADCM <- NULL if (isTRUE(select_plot()[cm_dataname])) { - ADCM <- data()[[cm_dataname]] + ADCM <- obj[[cm_dataname]] teal::validate_has_variable(ADCM, adcm_vars) } ADLB <- NULL if (isTRUE(select_plot()[lb_dataname])) { - ADLB <- data()[[lb_dataname]] + ADLB <- obj[[lb_dataname]] teal::validate_has_variable(ADLB, adlb_vars) } @@ -541,26 +543,26 @@ srv_g_patient_profile <- function(id, empty_ex <- FALSE empty_lb <- FALSE - q1 <- teal.code::eval_code(data(), "library(dplyr)") %>% - teal.code::eval_code( - code = substitute( - expr = { - ADSL <- ADSL %>% - filter(USUBJID == patient_id) %>% - group_by(USUBJID) %>% - mutate( - max_date = pmax(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), - max_day = as.numeric(difftime(as.Date(max_date), as.Date(sl_start_date), units = "days")) + - (as.Date(max_date) >= as.Date(sl_start_date)) - ) - }, - env = list( - ADSL = as.name(sl_dataname), - sl_start_date = as.name(sl_start_date), - patient_id = patient_id - ) + q1 <- teal.code::eval_code( + obj, + code = substitute( + expr = { + ADSL <- ADSL %>% + filter(USUBJID == patient_id) %>% + group_by(USUBJID) %>% + mutate( + max_date = pmax(as.Date(LSTALVDT), as.Date(DTHDT), na.rm = TRUE), + max_day = as.numeric(difftime(as.Date(max_date), as.Date(sl_start_date), units = "days")) + + (as.Date(max_date) >= as.Date(sl_start_date)) + ) + }, + env = list( + ADSL = as.name(sl_dataname), + sl_start_date = as.name(sl_start_date), + patient_id = patient_id ) ) + ) # ADSL with single subject validate( @@ -874,6 +876,8 @@ srv_g_patient_profile <- function(id, x_limit <- q1[["x_limit"]] } + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + q1 <- teal.code::eval_code( q1, code = substitute( @@ -914,26 +918,6 @@ srv_g_patient_profile <- function(id, title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Patient Profile", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_spiderplot.R b/R/tm_g_spiderplot.R index d26fd132..c1aa6b40 100644 --- a/R/tm_g_spiderplot.R +++ b/R/tm_g_spiderplot.R @@ -19,6 +19,7 @@ #' @param yfacet_var variable for y facets #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' @export #' #' @template author_zhanc107 @@ -146,10 +147,6 @@ ui_g_spider <- function(id, ...) { teal.widgets::plot_with_settings_ui(id = ns("spiderplot")) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), helpText("Analysis data:", tags$code(a$dataname)), left_bordered_div( @@ -247,9 +244,7 @@ ui_g_spider <- function(id, ...) { ) } -srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") +srv_g_spider <- function(id, data, dataname, paramcd, label, plot_height, plot_width) { checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -306,9 +301,18 @@ srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname # render plot output_q <- reactive({ + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Spider Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + # get datasets --- - ADSL <- data()[["ADSL"]] - ADTR <- data()[[dataname]] + ADSL <- obj[["ADSL"]] + ADTR <- obj[[dataname]] teal::validate_inputs(iv()) @@ -347,19 +351,18 @@ srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname adtr_vars <- adtr_vars[!is.null(adtr_vars)] # merge - q1 <- teal.code::eval_code(data(), "library(dplyr)") %>% - teal.code::eval_code( - code = bquote({ - ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() - ADTR <- .(as.name(dataname))[, .(adtr_vars)] %>% as.data.frame() - - ANL <- merge(ADSL, ADTR, by = c("USUBJID", "STUDYID")) - ANL <- ANL %>% - group_by(USUBJID, PARAMCD) %>% - arrange(ANL[, .(x_var)]) %>% - as.data.frame() - }) - ) + q1 <- teal.code::eval_code( + obj, + code = bquote({ + ADSL <- ADSL[, .(adsl_vars)] %>% as.data.frame() + ADTR <- .(as.name(dataname))[, .(adtr_vars)] %>% as.data.frame() + ANL <- merge(ADSL, ADTR, by = c("USUBJID", "STUDYID")) + ANL <- ANL %>% + group_by(USUBJID, PARAMCD) %>% + arrange(ANL[, .(x_var)]) %>% + as.data.frame() + }) + ) # format and filter q1 <- teal.code::eval_code( @@ -384,6 +387,23 @@ srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname # plot code to qenv --- + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + if (!is.null(input$paramcd) || !is.null(input$xfacet_var) || !is.null(input$yfacet_var)) { + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "### Selected Options") + } + if (!is.null(input$paramcd)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Parameter - (from ", dataname, "): ", input$paramcd, ".")) + } + if (!is.null(input$xfacet_var)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Faceted horizontally by: ", paste(input$xfacet_var, collapse = ", "), ".")) + } + if (!is.null(input$yfacet_var)) { + teal.reporter::teal_card(q1) <- + c(teal.reporter::teal_card(q1), paste0("Faceted vertically by: ", paste(input$yfacet_var, collapse = ", "), ".")) + } + q1 <- teal.code::eval_code( q1, code = bquote({ @@ -427,8 +447,6 @@ srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname }, show_legend = .(legend_on) ) - - plot }) ) }) @@ -447,38 +465,6 @@ srv_g_spider <- function(id, data, filter_panel_api, paramcd, reporter, dataname title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Spider Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - if (!is.null(input$paramcd) || !is.null(input$xfacet_var) || !is.null(input$yfacet_var)) { - card$append_text("Selected Options", "header3") - } - if (!is.null(input$paramcd)) { - card$append_text(paste0("Parameter - (from ", dataname, "): ", input$paramcd, ".")) - } - if (!is.null(input$xfacet_var)) { - card$append_text(paste0("Faceted horizontally by: ", paste(input$xfacet_var, collapse = ", "), ".")) - } - if (!is.null(input$yfacet_var)) { - card$append_text(paste0("Faceted vertically by: ", paste(input$yfacet_var, collapse = ", "), ".")) - } - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_swimlane.R b/R/tm_g_swimlane.R index d240edd4..10580f1c 100644 --- a/R/tm_g_swimlane.R +++ b/R/tm_g_swimlane.R @@ -29,6 +29,7 @@ #' @param x_label the label of the x axis #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -183,10 +184,6 @@ ui_g_swimlane <- function(id, ...) { teal.widgets::plot_with_settings_ui(id = ns("swimlaneplot")) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), helpText("Analysis data:", tags$code(a$dataname)), left_bordered_div( @@ -262,8 +259,6 @@ ui_g_swimlane <- function(id, ...) { srv_g_swimlane <- function(id, data, - filter_panel_api, - reporter, dataname, marker_pos_var, marker_shape_var, @@ -274,8 +269,6 @@ srv_g_swimlane <- function(id, plot_height, plot_width, x_label) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -324,18 +317,26 @@ srv_g_swimlane <- function(id, # create plot output_q <- reactive({ + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Swimlane Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + teal::validate_inputs(iv()) - validate(need("ADSL" %in% names(data()), "'ADSL' not included in data")) + validate(need("ADSL" %in% names(obj), "'ADSL' not included in data")) validate(need( - (length(data()) == 1 && dataname == "ADSL") || - (length(data()) >= 2 && dataname != "ADSL"), paste( + (length(obj) == 1 && dataname == "ADSL") || + (length(obj) >= 2 && dataname != "ADSL"), paste( "Please either add just 'ADSL' as dataname when just ADSL is available.", "In case 2 datasets are available ADSL is not supposed to be the dataname." ) )) - ADSL <- data()[["ADSL"]] + ADSL <- obj[["ADSL"]] anl_vars <- unique(c( "USUBJID", "STUDYID", @@ -350,7 +351,7 @@ srv_g_swimlane <- function(id, teal::validate_has_data(ADSL, min_nrow = 3) teal::validate_has_variable(ADSL, adsl_vars) } else { - anl <- data()[[dataname]] + anl <- obj[[dataname]] teal::validate_has_data(anl, min_nrow = 3) teal::validate_has_variable(anl, anl_vars) @@ -379,7 +380,7 @@ srv_g_swimlane <- function(id, } vref_line <- suppressWarnings(as_numeric_from_comma_sep_str(debounce(reactive(input$vref_line), 1500)())) - q1 <- data() + q1 <- obj q2 <- teal.code::eval_code( q1, @@ -504,8 +505,14 @@ srv_g_swimlane <- function(id, ) } - q4 <- teal.code::eval_code(q3, code = plot_call) - teal.code::eval_code(q4, quote(plot)) + teal.reporter::teal_card(q3) <- c(teal.reporter::teal_card(q3), "## Plot") + + if (!is.null(input$sort_var)) { + teal.reporter::teal_card(q3) <- c(teal.reporter::teal_card(q3), "### Selected Options") + teal.reporter::teal_card(q3) <- c(teal.reporter::teal_card(q3), paste("Sorted by:", input$sort_var)) + } + + teal.code::eval_code(q3, code = plot_call) }) plot_r <- reactive(output_q()[["plot"]]) @@ -523,30 +530,6 @@ srv_g_swimlane <- function(id, title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Swimlane Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - if (!is.null(input$sort_var)) { - card$append_text("Selected Options", "header3") - card$append_text(paste("Sorted by:", input$sort_var)) - } - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/tm_g_waterfall.R b/R/tm_g_waterfall.R index 622960de..e07af4a0 100644 --- a/R/tm_g_waterfall.R +++ b/R/tm_g_waterfall.R @@ -40,6 +40,7 @@ #' @param show_value boolean of whether value of bar height is shown, default is `TRUE` #' #' @inherit argument_convention return +#' @inheritSection teal::example_module Reporting #' #' @export #' @@ -160,10 +161,6 @@ ui_g_waterfall <- function(id, ...) { teal.widgets::plot_with_settings_ui(id = ns("waterfallplot")) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### tags$label("Encodings", class = "text-primary"), helpText("Analysis Data: ", tags$code(a$dataname_tr), tags$code(a$dataname_rs)), teal.widgets::optionalSelectInput( @@ -271,8 +268,6 @@ ui_g_waterfall <- function(id, ...) { srv_g_waterfall <- function(id, data, - filter_panel_api, - reporter, bar_paramcd, add_label_paramcd_rs, anno_txt_paramcd_rs, @@ -282,8 +277,6 @@ srv_g_waterfall <- function(id, label, plot_height, plot_width) { - with_reporter <- !missing(reporter) && inherits(reporter, "Reporter") - with_filter <- !missing(filter_panel_api) && inherits(filter_panel_api, "FilterPanelAPI") checkmate::assert_class(data, "reactive") checkmate::assert_class(shiny::isolate(data()), "teal_data") @@ -366,9 +359,18 @@ srv_g_waterfall <- function(id, }) output_q <- reactive({ - adsl <- data()[["ADSL"]] - adtr <- data()[[dataname_tr]] - adrs <- data()[[dataname_rs]] + obj <- data() + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Waterfall Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Module's code") + ) + obj <- teal.code::eval_code(obj, "library(dplyr)") + + adsl <- obj[["ADSL"]] + adtr <- obj[[dataname_tr]] + adrs <- obj[[dataname_rs]] # validate data rows teal::validate_has_data(adsl, min_nrow = 2) @@ -433,22 +435,22 @@ srv_g_waterfall <- function(id, } # write variables to qenv - q1 <- teal.code::eval_code(data(), "library(dplyr)") %>% - teal.code::eval_code( - code = bquote({ - bar_var <- .(bar_var) - bar_color_var <- .(bar_color_var) - sort_var <- .(sort_var) - add_label_var_sl <- .(add_label_var_sl) - add_label_paramcd_rs <- .(add_label_paramcd_rs) - anno_txt_var_sl <- .(anno_txt_var_sl) - anno_txt_paramcd_rs <- .(anno_txt_paramcd_rs) - facet_var <- .(facet_var) - href_line <- .(href_line) - gap_point_val <- .(gap_point_val) - show_value <- .(show_value) - }) - ) + q1 <- teal.code::eval_code( + obj, + code = bquote({ + bar_var <- .(bar_var) + bar_color_var <- .(bar_color_var) + sort_var <- .(sort_var) + add_label_var_sl <- .(add_label_var_sl) + add_label_paramcd_rs <- .(add_label_paramcd_rs) + anno_txt_var_sl <- .(anno_txt_var_sl) + anno_txt_paramcd_rs <- .(anno_txt_paramcd_rs) + facet_var <- .(facet_var) + href_line <- .(href_line) + gap_point_val <- .(gap_point_val) + show_value <- .(show_value) + }) + ) # data processing q1 <- teal.code::eval_code( @@ -501,6 +503,28 @@ srv_g_waterfall <- function(id, # write plotting code to qenv anl <- q1[["anl"]] + teal.reporter::teal_card(q1) <- + c( + teal.reporter::teal_card(q1), + "### Selected Options", + paste0("Tumor Burden Parameter: ", input$bar_paramcd, ".") + ) + + if (!is.null(facet_var)) { + teal.reporter::teal_card(q1) <- c( + teal.reporter::teal_card(q1), + paste0("Faceted by: ", paste(facet_var, collapse = ", "), ".") + ) + } + if (!is.null(sort_var)) { + teal.reporter::teal_card(q1) <- c( + teal.reporter::teal_card(q1), + paste0("Sorted by: ", paste(sort_var, collapse = ", "), ".") + ) + } + + teal.reporter::teal_card(q1) <- c(teal.reporter::teal_card(q1), "## Plot") + q1 <- teal.code::eval_code( q1, code = bquote({ @@ -572,34 +596,6 @@ srv_g_waterfall <- function(id, title = paste("R code for", label), verbatim_content = reactive(teal.code::get_code(output_q())) ) - - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- teal::report_card_template( - title = "Waterfall Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api - ) - card$append_text("Selected Options", "header3") - card$append_text(paste0("Tumor Burden Parameter: ", input$bar_paramcd, ".")) - if (!is.null(input$sort_var)) { - card$append_text(paste0("Sorted by: ", input$sort_var, ".")) - } - if (!is.null(input$facet_var)) { - card$append_text(paste0("Faceted by: ", paste(input$facet_var, collapse = ", "), ".")) - } - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = pws$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(teal.code::get_code(output_q())) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } + set_chunk_dims(pws, output_q) }) } diff --git a/R/utils.R b/R/utils.R index 96c4a2f0..1dfcf628 100644 --- a/R/utils.R +++ b/R/utils.R @@ -136,3 +136,106 @@ left_bordered_div <- function(...) { ... ) } + +#' Set the attributes of the last chunk outputs +#' +#' This function modifies the attributes of the last `n` elements of a `teal_card` +#' that are `chunk_output` objects. It can be used to set attributes like `dev.width` +#' and `dev.height` for plot outputs. +#' +#' @param teal_card (`teal_card`) the teal_card object to modify +#' @param attributes (`list`) named list of attributes to set +#' @param n (`integer(1)`) number of the last element of `teal_card` to modify. +#' it will only change `chunk_output` objects. +#' @param inner_classes (`character`) classes within `chunk_output` that should be modified. +#' This can be used to only change `recordedplot`, `ggplot2` or other type of objects. +#' @param quiet (`logical`) whether to suppress warnings +#' @keywords internal +set_chunk_attrs <- function(teal_card, + attributes, + n = 1, + inner_classes = NULL, + quiet = FALSE) { + checkmate::assert_class(teal_card, "teal_card") + checkmate::assert_list(attributes, names = "unique") + checkmate::assert_int(n, lower = 1) + checkmate::assert_character(inner_classes, null.ok = TRUE) + checkmate::assert_flag(quiet) + + if (!inherits(teal_card[[length(teal_card)]], "chunk_output")) { + if (!quiet) { + warning("The last element of the `teal_card` is not a `chunk_output` object. No attributes were modified.") + } + return(teal_card) + } + + for (ix in seq_len(length(teal_card))) { + if (ix > n) { + break + } + current_ix <- length(teal_card) + 1 - ix + if (!inherits(teal_card[[current_ix]], "chunk_output")) { + if (!quiet) { + warning( + "The ", ix, + " to last element of the `teal_card` is not a `chunk_output` object. Skipping any further modifications." + ) + } + return(teal_card) + } + + if ( + length(inner_classes) > 0 && + length(teal_card[[current_ix]]) >= 1 && + !checkmate::test_multi_class(teal_card[[current_ix]][[1]], inner_classes) + ) { + next + } + + attributes(teal_card[[current_ix]]) <- utils::modifyList( + attributes(teal_card[[current_ix]]), + attributes + ) + } + + teal_card +} + +#' Create a reactive that sets plot dimensions on a `teal_card` +#' +#' This is a convenience function that creates a reactive expression that +#' automatically sets the `dev.width` and `dev.height` attributes on the last +#' chunk outputs of a `teal_card` based on plot dimensions from a plot widget. +#' +#' @param pws (`plot_widget`) plot widget that provides dimensions via `dim()` method +#' @param q_r (`reactive`) reactive expression that returns a `teal_reporter` +#' @param inner_classes (`character`) classes within `chunk_output` that should be modified. +#' This can be used to only change `recordedplot`, `ggplot2` or other type of objects. +#' +#' @return A reactive expression that returns the `teal_card` with updated dimensions +#' +#' @keywords internal +set_chunk_dims <- function(pws, q_r, inner_classes = NULL) { + checkmate::assert_list(pws) + checkmate::assert_names(names(pws), must.include = "dim") + checkmate::assert_class(pws$dim, "reactive") + checkmate::assert_class(q_r, "reactive") + checkmate::assert_character(inner_classes, null.ok = TRUE) + + reactive({ + pws_dim <- stats::setNames(as.list(req(pws$dim())), c("width", "height")) + if (identical(pws_dim$width, "auto")) { # ignore non-numeric values (such as "auto") + pws_dim$width <- NULL + } + if (identical(pws_dim$height, "auto")) { # ignore non-numeric values (such as "auto") + pws_dim$height <- NULL + } + q <- req(q_r()) + teal.reporter::teal_card(q) <- set_chunk_attrs( + teal.reporter::teal_card(q), + list(dev.width = pws_dim$width, dev.height = pws_dim$height), + inner_classes = inner_classes + ) + q + }) +} diff --git a/man/set_chunk_attrs.Rd b/man/set_chunk_attrs.Rd new file mode 100644 index 00000000..8f657ea9 --- /dev/null +++ b/man/set_chunk_attrs.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{set_chunk_attrs} +\alias{set_chunk_attrs} +\title{Set the attributes of the last chunk outputs} +\usage{ +set_chunk_attrs( + teal_card, + attributes, + n = 1, + inner_classes = NULL, + quiet = FALSE +) +} +\arguments{ +\item{teal_card}{(\code{teal_card}) the teal_card object to modify} + +\item{attributes}{(\code{list}) named list of attributes to set} + +\item{n}{(\code{integer(1)}) number of the last element of \code{teal_card} to modify. +it will only change \code{chunk_output} objects.} + +\item{inner_classes}{(\code{character}) classes within \code{chunk_output} that should be modified. +This can be used to only change \code{recordedplot}, \code{ggplot2} or other type of objects.} + +\item{quiet}{(\code{logical}) whether to suppress warnings} +} +\description{ +This function modifies the attributes of the last \code{n} elements of a \code{teal_card} +that are \code{chunk_output} objects. It can be used to set attributes like \code{dev.width} +and \code{dev.height} for plot outputs. +} +\keyword{internal} diff --git a/man/set_chunk_dims.Rd b/man/set_chunk_dims.Rd new file mode 100644 index 00000000..aea85363 --- /dev/null +++ b/man/set_chunk_dims.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{set_chunk_dims} +\alias{set_chunk_dims} +\title{Create a reactive that sets plot dimensions on a \code{teal_card}} +\usage{ +set_chunk_dims(pws, q_r, inner_classes = NULL) +} +\arguments{ +\item{pws}{(\code{plot_widget}) plot widget that provides dimensions via \code{dim()} method} + +\item{q_r}{(\code{reactive}) reactive expression that returns a \code{teal_reporter}} + +\item{inner_classes}{(\code{character}) classes within \code{chunk_output} that should be modified. +This can be used to only change \code{recordedplot}, \code{ggplot2} or other type of objects.} +} +\value{ +A reactive expression that returns the \code{teal_card} with updated dimensions +} +\description{ +This is a convenience function that creates a reactive expression that +automatically sets the \code{dev.width} and \code{dev.height} attributes on the last +chunk outputs of a \code{teal_card} based on plot dimensions from a plot widget. +} +\keyword{internal}