diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index e5bbc62d0..c3d974db4 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -999,12 +999,14 @@ srv_a_pca <- function(id, data, reporter, filter_panel_api, dat, plot_height, pl ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("PCA Plot") - card$append_text("PCA Plot", "header2") - card$append_text("Principal Component Analysis Plot", "header3") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "PCA Plot", + label = label, + description = "Principal Component Analysis Plot", + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) card$append_text("Principal Components Table", "header3") card$append_table(computation()[["tbl_importance"]]) card$append_text("Eigenvectors Table", "header3") diff --git a/R/tm_a_regression.R b/R/tm_a_regression.R index e7f3650d8..7580187c1 100644 --- a/R/tm_a_regression.R +++ b/R/tm_a_regression.R @@ -869,11 +869,14 @@ srv_a_regression <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Linear Regression Plot") - card$append_text("Linear Regression Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Linear Regression Plot", + label = label, + description = NULL, + 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 == "") { diff --git a/R/tm_g_association.R b/R/tm_g_association.R index ca524a1e6..1958f900f 100644 --- a/R/tm_g_association.R +++ b/R/tm_g_association.R @@ -458,10 +458,14 @@ srv_tm_g_association <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Association Plot") - card$append_text("Association Plot", "header2") + card_fun <- function(comment, label) { + card <- card_template( + title = "Association Plot", + label = label, + description = NULL, + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) card$append_text("Plot", "header3") card$append_plot(plot_r(), dim = pws$dim()) diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 464f6e19f..04a4c7d1e 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -620,11 +620,14 @@ srv_g_bivariate <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Bivariate Plot") - card$append_text("Bivariate Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Bivariate Plot", + label = label, + description = NULL, + 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 == "") { diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index 9fa6eaaad..65af8cd6a 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -1225,11 +1225,14 @@ srv_distribution <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Distribution Plot") - card$append_text("Distribution Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Distribution Plot", + label = label, + description = NULL, + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) card$append_text("Plot", "header3") if (input$tabs == "Histogram") { card$append_plot(dist_r(), dim = pws1$dim()) diff --git a/R/tm_g_response.R b/R/tm_g_response.R index 483a6a1c3..670e3adfd 100644 --- a/R/tm_g_response.R +++ b/R/tm_g_response.R @@ -476,11 +476,14 @@ srv_g_response <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Response Plot") - card$append_text("Response Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Response Plot", + label = label, + description = NULL, + 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 == "") { diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index f7aea4ff2..caa489f9a 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -948,11 +948,14 @@ srv_g_scatterplot <- function(id, ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Scatter Plot") - card$append_text("Scatter Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Scatter Plot", + label = label, + description = NULL, + 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 == "") { diff --git a/R/tm_g_scatterplotmatrix.R b/R/tm_g_scatterplotmatrix.R index 8a2b8cf3e..f2225728a 100644 --- a/R/tm_g_scatterplotmatrix.R +++ b/R/tm_g_scatterplotmatrix.R @@ -353,11 +353,14 @@ srv_g_scatterplotmatrix <- function(id, data, reporter, filter_panel_api, variab ### REPORTER if (with_reporter) { - card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Scatter Plot Matrix") - card$append_text("Scatter Plot Matrix", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card_fun <- function(comment, label) { + card <- card_template( + title = "Scatter Plot Matrix", + label = label, + description = NULL, + 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 == "") { diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index 475dad2fd..5c2d0727c 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -1200,12 +1200,15 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par ### REPORTER if (with_reporter) { - card_fun <- function(comment) { + card_fun <- function(comment, label) { card <- teal::TealReportCard$new() sum_type <- input$summary_type title <- if (sum_type == "By Variable Levels") paste0(sum_type, " Table") else paste0(sum_type, " Plot") title_dataname <- paste(title, dataname, sep = " - ") - card$set_name(paste("Missing Data", sum_type, dataname, sep = " - ")) + label <- if (label == "") { + paste("Missing Data", sum_type, dataname, sep = " - ") + } else { label } + card$set_name(label) card$append_text(title_dataname, "header2") if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) if (sum_type == "Summary") { diff --git a/R/tm_outliers.R b/R/tm_outliers.R index fba0c5ceb..8a0e43911 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -1147,12 +1147,14 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ### REPORTER if (with_reporter) { card_fun <- function(comment) { - card <- teal::TealReportCard$new() tab_type <- input$tabs - card$set_name(paste0("Outliers - ", tab_type)) - card$append_text(tab_type, "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) - + card <- card_template( + title = paste0("Outliers - ", tab_type), + label = label, + description = NULL, + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) categorical_var <- as.vector(merged$anl_input_r()$columns_source$categorical_var) if (length(categorical_var) > 0) { summary_table <- common_code_q()[["summary_table"]] diff --git a/R/tm_t_crosstable.R b/R/tm_t_crosstable.R index 0d864c293..328707185 100644 --- a/R/tm_t_crosstable.R +++ b/R/tm_t_crosstable.R @@ -352,10 +352,13 @@ srv_t_crosstable <- function(id, data, reporter, filter_panel_api, label, x, y, ### REPORTER if (with_reporter) { card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Cross Table") - card$append_text("Cross Table", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card <- card_template( + title = "Cross Table", + label = label, + description = NULL, + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) card$append_text("Table", "header3") card$append_table(table_r()) if (!comment == "") { diff --git a/R/tm_variable_browser.R b/R/tm_variable_browser.R index 24eea5744..43922760d 100644 --- a/R/tm_variable_browser.R +++ b/R/tm_variable_browser.R @@ -501,10 +501,13 @@ srv_variable_browser <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment) { - card <- teal::TealReportCard$new() - card$set_name("Variable Browser Plot") - card$append_text("Variable Browser Plot", "header2") - if (with_filter) card$append_fs(filter_panel_api$get_filter_state()) + card <- card_template( + title = "Variable Browser Plot", + label = label, + description = NULL, + with_filter = with_filter, + filter_panel_api = filter_panel_api + ) card$append_text("Plot", "header3") card$append_plot(variable_plot_r(), dim = pws$dim()) if (!comment == "") { diff --git a/R/utils.R b/R/utils.R index 07db56a98..ac86375a9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -350,3 +350,28 @@ is_tab_active_js <- function(id, name) { id, name ) } + +#' Template function to generate reporter card for `teal.modules.general` +#' @param title (`character(1)`) title of the card (unless overwritten by label) +#' @param label (`character(1)`) label provided by the user when adding the card +#' @param description (`character(1)`) optional additional description +#' @param with_filter (`logical(1)`) flag indicating to add filter state +#' @param filter_panel_api (`FilterPanelAPI`) object with API that allows the generation +#' of the filter state in the report +#' +#' @return (`TealReportCard`) populated with a title, description and filter state +#' +#' @keywords internal +card_template <- function(title, label, description = NULL, with_filter = FALSE, filter_panel_api = NULL) { + card <- teal::TealReportCard$new() + title <- if (label == "") title else label + card$set_name(title) + card$append_text(title, "header2") + if (!is.null(description)) { + card$append_text(description, "header3") + } + if (with_filter) { + card$append_fs(filter_panel_api$get_filter_state()) + } + card +} diff --git a/man/card_template.Rd b/man/card_template.Rd new file mode 100644 index 000000000..cbf6efddd --- /dev/null +++ b/man/card_template.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{card_template} +\alias{card_template} +\title{Template function to generate reporter card for \code{teal.modules.general}} +\usage{ +card_template( + title, + label, + description = NULL, + with_filter = FALSE, + filter_panel_api = NULL +) +} +\arguments{ +\item{title}{(\code{character(1)}) title of the card (unless overwritten by label)} + +\item{label}{(\code{character(1)}) label provided by the user when adding the card} + +\item{description}{(\code{character(1)}) optional additional description} + +\item{with_filter}{(\code{logical(1)}) flag indicating to add filter state} + +\item{filter_panel_api}{(\code{FilterPanelAPI}) object with API that allows the generation +of the filter state in the report} +} +\value{ +(\code{TealReportCard}) populated with a title, description and filter state +} +\description{ +Template function to generate reporter card for \code{teal.modules.general} +} +\keyword{internal}