Skip to content

Commit

Permalink
add card_template function and allow to pass label to reporter card c…
Browse files Browse the repository at this point in the history
…ontent
  • Loading branch information
kartikeyakirar committed Oct 4, 2023
1 parent ecca50b commit f2f1d15
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 55 deletions.
14 changes: 8 additions & 6 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 8 additions & 5 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
12 changes: 8 additions & 4 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 8 additions & 5 deletions R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
13 changes: 8 additions & 5 deletions R/tm_g_distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
13 changes: 8 additions & 5 deletions R/tm_g_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
13 changes: 8 additions & 5 deletions R/tm_g_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
13 changes: 8 additions & 5 deletions R/tm_g_scatterplotmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
7 changes: 5 additions & 2 deletions R/tm_missing_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
12 changes: 7 additions & 5 deletions R/tm_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
11 changes: 7 additions & 4 deletions R/tm_t_crosstable.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
11 changes: 7 additions & 4 deletions R/tm_variable_browser.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "") {
Expand Down
25 changes: 25 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
33 changes: 33 additions & 0 deletions man/card_template.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f2f1d15

Please sign in to comment.