Skip to content

Commit

Permalink
198 Include user's card labels when generating the report (#241)
Browse files Browse the repository at this point in the history
this PR fixes
#240

this is follow-up after
insightsengineering/teal.reporter#219

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 13, 2023
1 parent 6fb64c3 commit 81ae566
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 70 deletions.
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
linters: linters_with_defaults(
line_length_linter = line_length_linter(120),
cyclocomp_linter = NULL,
object_usage_linter = NULL
object_usage_linter = NULL,
indentation_linter = NULL
)
30 changes: 17 additions & 13 deletions R/tm_g_gh_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -548,20 +548,24 @@ srv_g_boxplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Box Plot")
card$append_text("Box Plot", "header2")
if (with_filter) card$append_fs(filter_panel_api$get_filter_state())
card$append_text("Selected Options", "header3")
card$append_text(
paste(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max),
"\nFacet By:",
if (length(input$facet_var) != 0) input$facet_var else "None",
"\nSelect an X-axis Variable:",
input$xaxis_var
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")
Expand Down
30 changes: 17 additions & 13 deletions R/tm_g_gh_correlationplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -875,20 +875,24 @@ srv_g_correlationplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Correlation Plot")
card$append_text("Correlation Plot", "header2")
if (with_filter) card$append_fs(filter_panel_api$get_filter_state())
card$append_text("Selected Options", "header3")
card$append_text(
paste(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max),
"\nTreatment Variable Faceting:",
input$trt_facet,
"\nRegression Line:",
input$reg_line
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")
Expand Down
19 changes: 11 additions & 8 deletions R/tm_g_gh_density_distribution_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,17 @@ srv_g_density_distribution_plot <- function(id, # nolint

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Density Distribution Plot")
card$append_text("Density Distribution Plot", "header2")
if (with_filter) card$append_fs(filter_panel_api$get_filter_state())
card$append_text("Selected Options", "header3")
card$append_text(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max)
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())
Expand Down
30 changes: 17 additions & 13 deletions R/tm_g_gh_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -793,20 +793,24 @@ srv_lineplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Line Plot")
card$append_text("Line Plot", "header2")
if (with_filter) card$append_fs(filter_panel_api$get_filter_state())
card$append_text("Selected Options", "header3")
card$append_text(
paste(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max),
"\nSelect Line Splitting Variable:",
if (!is.null(input$shape)) input$shape else "None",
"\nContributing Observations Threshold:",
input$count_threshold
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")
Expand Down
30 changes: 17 additions & 13 deletions R/tm_g_gh_scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,24 @@ 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$append_text("Selected Options", "header3")
card$append_text(
paste(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max),
"\nTreatment Variable Faceting:",
input$trt_facet,
"\nRegression Line:",
input$reg_line
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 = "Scatter 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("Scatter Plot", "header3")
Expand Down
19 changes: 11 additions & 8 deletions R/tm_g_gh_spaghettiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,17 @@ srv_g_spaghettiplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Spaghetti Plot")
card$append_text("Spaghetti Plot", "header2")
if (with_filter) card$append_fs(filter_panel_api$get_filter_state())
card$append_text("Selected Options", "header3")
card$append_text(
formatted_data_constraint(input$constraint_var, input$constraint_range_min, input$constraint_range_max)
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())
Expand Down
2 changes: 1 addition & 1 deletion R/utils-data_constraints.r
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ create_anl_constraint_reactive <- function(anl_param, input, param_id, min_rows)
)
}

# for outputting the constaint in the report
# for outputting the constraint in the report
formatted_data_constraint <- function(constraint_var, constraint_range_min, constraint_range_max) {
constraint_var_label <- switch(constraint_var,
"BASE2" = "Screening",
Expand Down
51 changes: 51 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,54 @@ plots_per_row_validate_rules <- function(required = TRUE) {
shinyvalidate::sv_gt(0, message_fmt = msg)
)
}

#' Template Function for `TealReportCard` Creation and Customization in `teal.goshawk`
#'
#' This function generates a report card with a title,
#' an optional description, and the option to append the filter state list.
#' Additionally, it display selected constraint options.
#'
#' @inheritParams teal.reporter::card_template
#' @param constraint_list (`list`) a list containing constraint variables, including:
#' - constraint_var (`character(1)`) the constraint variable name.
#' - constraint_range_min (`numeric(1)`) the minimum constraint range value.
#' - constraint_range_max (`numeric(1)`) the maximum constraint range value.
#' @param constraint_description (`character(1)`) description of the constraints.
#' @param style (`character(1)`) style of the constraint text block.
#' options: `default`, `verbatim` (default is `default`).
#'
#' @return (`TealReportCard`) populated with a title, description, and filter state
#'
#' @keywords internal
report_card_template_goshawk <- function(title,
label,
with_filter,
filter_panel_api,
constraint_list,
constraint_description = NULL,
style = "default") {
checkmate::assert_subset(names(constraint_list), c("constraint_var", "constraint_range_min", "constraint_range_max"))
checkmate::assert_string(constraint_description, null.ok = TRUE)
checkmate::assert_choice(style, c("default", "verbatim"))

card <- teal::report_card_template(
title = title,
label = label,
with_filter = with_filter,
filter_panel_api = filter_panel_api
)

card$append_text("Selected Options", "header3")
card$append_text(
paste(
formatted_data_constraint(
constraint_list$constraint_var,
constraint_list$constraint_range_min,
constraint_list$constraint_range_max
),
constraint_description
),
style = style
)
card
}
38 changes: 38 additions & 0 deletions man/report_card_template_goshawk.Rd

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

0 comments on commit 81ae566

Please sign in to comment.