diff --git a/DESCRIPTION b/DESCRIPTION index 9ad3f5c3..911bd8fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -32,7 +32,7 @@ Depends: goshawk (>= 0.1.19), 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), @@ -50,7 +50,7 @@ Imports: stats, teal.code (>= 0.7.0), teal.logger (>= 0.4.0), - teal.reporter (>= 0.5.0), + teal.reporter (>= 0.5.0.9001), teal.widgets (>= 0.5.0) Suggests: knitr (>= 1.42), @@ -59,7 +59,7 @@ Suggests: rvest (>= 1.0.0), shinytest2 (>= 0.4.1), stringr (>= 1.4.1), - teal.data (>= 0.7.0), + teal.data (>= 0.7.0.9002), tern (>= 0.9.7), testthat (>= 3.2.3), utils @@ -67,6 +67,8 @@ VignetteBuilder: knitr, rmarkdown Remotes: + insightsengineering/teal, + insightsengineering/teal.reporter, insightsengineering/goshawk Config/Needs/verdepcheck: insightsengineering/goshawk, rstudio/shiny, insightsengineering/teal, insightsengineering/teal.slice, @@ -85,4 +87,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_gh_boxplot.R b/R/tm_g_gh_boxplot.R index a409328f..e8c6ee70 100644 --- a/R/tm_g_gh_boxplot.R +++ b/R/tm_g_gh_boxplot.R @@ -42,6 +42,8 @@ #' @author Jeff Tomlinson (tomlinsj) jeffrey.tomlinson@roche.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' +#' @inheritSection teal::example_module Reporting +#' #' @return an \code{\link[teal]{module}} object #' #' @export @@ -240,10 +242,6 @@ ui_g_boxplot <- function(id, ...) { ) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### templ_ui_dataname(a$dataname), uiOutput(ns("axis_selections")), templ_ui_constraint(ns, label = "Data Constraint"), # required by constr_anl_q @@ -287,8 +285,6 @@ ui_g_boxplot <- function(id, ...) { srv_g_boxplot <- function(id, data, - reporter, - filter_panel_api, dataname, param_var, trt_group, @@ -299,8 +295,6 @@ srv_g_boxplot <- function(id, hline_vars_colors, hline_vars_labels, module_args) { - 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") @@ -383,7 +377,6 @@ srv_g_boxplot <- function(id, create_plot <- debounce(reactive({ teal::validate_inputs(iv_r()) - req(anl_q()) # nolint start param <- input$xaxis_param @@ -426,7 +419,30 @@ srv_g_boxplot <- function(id, ) } - anl_q()$qenv %>% teal.code::eval_code( + obj <- anl_q()$qenv + + constraint_description <- c( + paste("\nFacet By:", if (length(input$facet_var) != 0) input$facet_var else "None"), + paste("\nSelect an X-axis Variable:", input$xaxis_var) + ) + + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Box Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card( + "## Selected Options", + formatted_data_constraint( + constraint_var = input$xaxis_param, + constraint_range_min = input$constraint_range_min, + constraint_range_max = input$constraint_range_max + ), + constraint_description + ), + teal.reporter::teal_card("## Plot") + ) + + obj %>% teal.code::eval_code( code = bquote({ p <- goshawk::g_boxplot( data = ANL, @@ -512,41 +528,6 @@ srv_g_boxplot <- function(id, code <- reactive(teal.code::get_code(joined_qenvs())) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - constraint_description <- paste( - "\nFacet By:", - if (length(input$facet_var) != 0) input$facet_var else "None", - "\nSelect an X-axis Variable:", - input$xaxis_var - ) - card <- report_card_template_goshawk( - title = "Box Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api, - constraint_list = list( - constraint_var = input$constraint_var, - constraint_range_min = input$constraint_range_min, - constraint_range_max = input$constraint_range_max - ), - constraint_description = constraint_description, - style = "verbatim" - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = boxplot_data$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(code()) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } - ### - # highlight plot area reactive_df <- debounce(reactive({ boxplot_brush <- boxplot_data$brush() @@ -584,5 +565,6 @@ srv_g_boxplot <- function(id, verbatim_content = reactive(code()), title = "Show R Code for Boxplot" ) + set_chunk_dims(boxplot_data, create_plot) }) } diff --git a/R/tm_g_gh_correlationplot.R b/R/tm_g_gh_correlationplot.R index 18704053..3491bc80 100644 --- a/R/tm_g_gh_correlationplot.R +++ b/R/tm_g_gh_correlationplot.R @@ -50,6 +50,9 @@ #' @author Nick Paszty (npaszty) paszty.nicholas@gene.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' +#' @inheritSection teal::example_module Reporting +#' +#' #' @examples #' # Example using ADaM structure analysis dataset. #' data <- teal_data() @@ -278,10 +281,6 @@ ui_g_correlationplot <- function(id, ...) { teal.widgets::standard_layout( output = templ_ui_output_datatable(ns), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### templ_ui_dataname(a$dataname), uiOutput(ns("axis_selections")), templ_ui_constraint(ns, "X-Axis Data Constraint"), # required by constr_anl_q @@ -352,8 +351,6 @@ ui_g_correlationplot <- function(id, ...) { srv_g_correlationplot <- function(id, data, - reporter, - filter_panel_api, dataname, param_var, trt_group, @@ -367,8 +364,6 @@ srv_g_correlationplot <- function(id, vline_vars_colors, vline_vars_labels, module_args) { - 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") @@ -775,8 +770,16 @@ srv_g_correlationplot <- function(id, validate(need(input$trt_group, "Please select a treatment variable")) trt_group <- input$trt_group + obj <- plot_data_transpose()$qenv + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Correlation Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Plot") + ) + teal.code::eval_code( - object = plot_data_transpose()$qenv, + object = obj, code = bquote({ # re-establish treatment variable label p <- goshawk::g_correlationplot( @@ -836,41 +839,6 @@ srv_g_correlationplot <- function(id, code <- reactive(teal.code::get_code(plot_q())) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - constraint_description <- paste( - "\nTreatment Variable Faceting:", - input$trt_facet, - "\nRegression Line:", - input$reg_line - ) - card <- report_card_template_goshawk( - title = "Correlation Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api, - constraint_list = list( - constraint_var = input$constraint_var, - constraint_range_min = input$constraint_range_min, - constraint_range_max = input$constraint_range_max - ), - constraint_description = constraint_description, - style = "verbatim" - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = plot_data$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(code()) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } - ### - reactive_df <- debounce(reactive({ req(iv_r()$is_valid()) plot_brush <- plot_data$brush() @@ -901,5 +869,6 @@ srv_g_correlationplot <- function(id, verbatim_content = reactive(code()), title = "Show R Code for Correlation Plot" ) + set_chunk_dims(plot_data, plot_q) }) } diff --git a/R/tm_g_gh_density_distribution_plot.R b/R/tm_g_gh_density_distribution_plot.R index efb4c3c1..dca4c76e 100644 --- a/R/tm_g_gh_density_distribution_plot.R +++ b/R/tm_g_gh_density_distribution_plot.R @@ -31,6 +31,7 @@ #' #' @author Nick Paszty (npaszty) paszty.nicholas@gene.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com +#' @inheritSection teal::example_module Reporting #' #' @details None #' @@ -195,10 +196,6 @@ ui_g_density_distribution_plot <- function(id, ...) { ) ), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### templ_ui_dataname(a$dataname), uiOutput(ns("axis_selections")), templ_ui_constraint(ns, label = "Data Constraint"), @@ -242,8 +239,6 @@ ui_g_density_distribution_plot <- function(id, ...) { srv_g_density_distribution_plot <- function(id, # nolint data, - reporter, - filter_panel_api, dataname, param_var, param, @@ -253,8 +248,6 @@ srv_g_density_distribution_plot <- function(id, # nolint plot_height, plot_width, module_args) { - 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") @@ -346,8 +339,16 @@ srv_g_density_distribution_plot <- function(id, # nolint # nolint end + obj <- anl_q()$qenv + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Density Distribution Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Plot") + ) + teal.code::eval_code( - object = anl_q()$qenv, + object = obj, code = bquote({ p <- goshawk::g_density_distribution_plot( data = ANL, @@ -373,16 +374,31 @@ srv_g_density_distribution_plot <- function(id, # nolint ) }), 800) + plot_r <- reactive({ + create_plot()[["p"]] + }) + + plot_data <- teal.widgets::plot_with_settings_srv( + id = "plot", + plot_r = plot_r, + height = plot_height, + width = plot_width, + ) + + create_plot_dims <- set_chunk_dims(plot_data, create_plot) + create_table <- debounce(reactive({ req(iv_r()$is_valid()) - req(anl_q()) + req(create_plot_dims()) param <- input$xaxis_param xaxis_var <- input$xaxis_var font_size <- input$font_size trt_group <- input$trt_group + obj <- create_plot_dims() + teal.reporter::teal_card(obj) <- c(teal.reporter::teal_card(obj), "## Descriptive Statistics") teal.code::eval_code( - object = anl_q()$qenv, + object = obj, code = bquote({ tbl <- goshawk::t_summarytable( data = ANL, @@ -397,17 +413,6 @@ srv_g_density_distribution_plot <- function(id, # nolint ) }), 800) - plot_r <- reactive({ - create_plot()[["p"]] - }) - - plot_data <- teal.widgets::plot_with_settings_srv( - id = "plot", - plot_r = plot_r, - height = plot_height, - width = plot_width, - ) - output$table_ui <- DT::renderDataTable({ req(create_table()) tbl <- create_table()[["tbl"]] @@ -419,12 +424,7 @@ srv_g_density_distribution_plot <- function(id, # nolint DT::formatRound(numeric_cols, 2) }) - joined_qenvs <- reactive({ - req(create_plot(), create_table()) - c(create_plot(), create_table()) - }) - - code <- reactive(teal.code::get_code(joined_qenvs())) + code <- reactive(teal.code::get_code(create_table())) teal.widgets::verbatim_popup_srv( id = "rcode", @@ -432,35 +432,6 @@ srv_g_density_distribution_plot <- function(id, # nolint title = "Show R Code for Density Distribution Plot" ) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- report_card_template_goshawk( - title = "Density Distribution Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api, - constraint_list = list( - constraint_var = input$constraint_var, - constraint_range_min = input$constraint_range_min, - constraint_range_max = input$constraint_range_max - ) - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = plot_data$dim()) - card$append_text("Descriptive Statistics", "header3") - card$append_table( - create_table()[["tbl"]] %>% dplyr::mutate_if(is.numeric, round, 2) - ) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(code()) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } - ### + create_table }) } diff --git a/R/tm_g_gh_lineplot.R b/R/tm_g_gh_lineplot.R index b9678641..618a4578 100644 --- a/R/tm_g_gh_lineplot.R +++ b/R/tm_g_gh_lineplot.R @@ -45,6 +45,8 @@ #' @param dot_size plot dot size. #' @param plot_relative_height_value numeric value between 500 and 5000 for controlling the starting value #' of the relative plot height slider +#' @inheritSection teal::example_module Reporting +#' #' @author Wenyi Liu (luiw2) wenyi.liu@roche.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' @@ -235,10 +237,6 @@ ui_lineplot <- function(id, ...) { teal.widgets::standard_layout( output = teal.widgets::plot_with_settings_ui(id = ns("plot")), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### templ_ui_dataname(a$dataname), uiOutput(ns("axis_selections")), uiOutput(ns("shape_ui")), @@ -328,8 +326,6 @@ ui_lineplot <- function(id, ...) { srv_lineplot <- function(id, data, - reporter, - filter_panel_api, dataname, param_var, trt_group, @@ -343,8 +339,6 @@ srv_lineplot <- function(id, plot_height, plot_width, module_args) { - 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") @@ -706,10 +700,7 @@ srv_lineplot <- function(id, } else if (methods::is(xtick, "waiver")) { private_qenv <- teal.code::eval_code( object = private_qenv, - code = " - xtick <- ggplot2::waiver() - xlabel <- ggplot2::waiver() - " + code = "xtick <- ggplot2::waiver();xlabel <- ggplot2::waiver()" ) } @@ -717,8 +708,16 @@ srv_lineplot <- function(id, hline_arb_label <- horizontal_line()$line_arb_label hline_arb_color <- horizontal_line()$line_arb_color + obj <- private_qenv + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Line Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Plot") + ) + teal.code::eval_code( - object = private_qenv, + object = obj, code = bquote({ p <- goshawk::g_lineplot( data = ANL[stats::complete.cases(ANL[, c(.(yaxis), .(xaxis))]), ], @@ -766,45 +765,12 @@ srv_lineplot <- function(id, code <- reactive(teal.code::get_code(plot_q())) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - constraint_description <- paste( - "\nSelect Line Splitting Variable:", - if (!is.null(input$shape)) input$shape else "None", - "\nContributing Observations Threshold:", - input$count_threshold - ) - card <- report_card_template_goshawk( - title = "Line Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api, - constraint_list = list( - constraint_var = input$constraint_var, - constraint_range_min = input$constraint_range_min, - constraint_range_max = input$constraint_range_max - ), - constraint_description = constraint_description, - style = "verbatim" - ) - card$append_text("Plot", "header3") - card$append_plot(plot_r(), dim = plot_data$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(code()) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } - ### - teal.widgets::verbatim_popup_srv( id = "rcode", verbatim_content = reactive(code()), title = "Show R Code for Line Plot" ) + + set_chunk_dims(plot_data, plot_q) }) } diff --git a/R/tm_g_gh_spaghettiplot.R b/R/tm_g_gh_spaghettiplot.R index b532dc5c..1d798958 100644 --- a/R/tm_g_gh_spaghettiplot.R +++ b/R/tm_g_gh_spaghettiplot.R @@ -52,6 +52,8 @@ #' @author Wenyi Liu (luiw2) wenyi.liu@roche.com #' @author Balazs Toth (tothb2) toth.balazs@gene.com #' +#' @inheritSection teal::example_module Reporting +#' #' @return \code{shiny} object #' #' @export @@ -273,10 +275,6 @@ g_ui_spaghettiplot <- function(id, ...) { teal.widgets::standard_layout( output = templ_ui_output_datatable(ns), encoding = tags$div( - ### Reporter - teal.reporter::add_card_button_ui(ns("add_reporter"), label = "Add Report Card"), - tags$br(), tags$br(), - ### templ_ui_dataname(a$dataname), uiOutput(ns("axis_selections")), radioButtons( @@ -342,8 +340,6 @@ g_ui_spaghettiplot <- function(id, ...) { srv_g_spaghettiplot <- function(id, data, - reporter, - filter_panel_api, dataname, idvar, param_var, @@ -360,8 +356,6 @@ srv_g_spaghettiplot <- function(id, hline_vars_colors, hline_vars_labels, module_args) { - 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") @@ -479,8 +473,15 @@ srv_g_spaghettiplot <- function(id, ) } + obj <- private_qenv + teal.reporter::teal_card(obj) <- + c( + teal.reporter::teal_card("# Spaghetti Plot"), + teal.reporter::teal_card(obj), + teal.reporter::teal_card("## Plot") + ) teal.code::eval_code( - object = private_qenv, + object = obj, code = bquote({ p <- goshawk::g_spaghettiplot( data = ANL, @@ -529,34 +530,8 @@ srv_g_spaghettiplot <- function(id, brushing = TRUE ) - code <- reactive(teal.code::get_code(plot_q())) - ### REPORTER - if (with_reporter) { - card_fun <- function(comment, label) { - card <- report_card_template_goshawk( - title = "Spaghetti Plot", - label = label, - with_filter = with_filter, - filter_panel_api = filter_panel_api, - constraint_list = list( - constraint_var = input$constraint_var, - constraint_range_min = input$constraint_range_min, - constraint_range_max = input$constraint_range_max - ) - ) - card$append_text("Spaghetti Plot", "header3") - card$append_plot(plot_r(), dim = plot_data$dim()) - if (!comment == "") { - card$append_text("Comment", "header3") - card$append_text(comment) - } - card$append_src(code()) - card - } - teal.reporter::add_card_button_srv("add_reporter", reporter = reporter, card_fun = card_fun) - } - ### + code <- reactive(teal.code::get_code(plot_q())) reactive_df <- debounce(reactive({ plot_brush <- plot_data$brush() @@ -594,5 +569,6 @@ srv_g_spaghettiplot <- function(id, verbatim_content = reactive(code()), title = "Show R Code for Spaghetti Plot" ) + set_chunk_dims(plot_data, plot_q) }) } diff --git a/R/utils.R b/R/utils.R index 277b1590..f73dac14 100644 --- a/R/utils.R +++ b/R/utils.R @@ -91,3 +91,96 @@ get_choices <- function(choices) { choices } } + +#' Set the attributes of the last chunk outputs +#' @param teal_card (`teal_card`) object to modify. +#' @param attributes (`list`) of attributes to set on the last chunk outputs. +#' @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. +#' @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 && !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..c82f11b0 --- /dev/null +++ b/man/set_chunk_attrs.Rd @@ -0,0 +1,29 @@ +% 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}) object to modify.} + +\item{attributes}{(\code{list}) of attributes to set on the last chunk outputs.} + +\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.} +} +\description{ +Set the attributes of the last chunk 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} diff --git a/man/tm_g_gh_boxplot.Rd b/man/tm_g_gh_boxplot.Rd index b50662d3..965136a3 100644 --- a/man/tm_g_gh_boxplot.Rd +++ b/man/tm_g_gh_boxplot.Rd @@ -108,7 +108,7 @@ This teal module renders the UI and calls the functions that create a box plot a summary table. } \examples{ -\dontshow{if (require("nestcolor")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("nestcolor")) withAutoprint(\{ # examplesIf} # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, { diff --git a/man/tm_g_gh_lineplot.Rd b/man/tm_g_gh_lineplot.Rd index 4242e364..5a960232 100644 --- a/man/tm_g_gh_lineplot.Rd +++ b/man/tm_g_gh_lineplot.Rd @@ -127,7 +127,7 @@ To learn more check \code{vignette("transform-input-data", package = "teal")}.} This teal module renders the UI and calls the function that creates a line plot. } \examples{ -\dontshow{if (require("nestcolor")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +\dontshow{if (require("nestcolor")) withAutoprint(\{ # examplesIf} # Example using ADaM structure analysis dataset. data <- teal_data() data <- within(data, {