From 57fdce91b2c599f1819ef8088669a7ae2bc2fbf2 Mon Sep 17 00:00:00 2001 From: kartikeya kirar Date: Fri, 13 Oct 2023 15:14:58 +0530 Subject: [PATCH 1/2] 198 extension to Include user's card labels when generating the report (#933) this PR is extension to https://github.com/insightsengineering/teal.reporter/issues/198 Here I have added card_template() function that generates a report card with a title, an optional description, and the option to append the filter state list. and is been used in https://github.com/insightsengineering/teal.modules.general/pull/584 https://github.com/insightsengineering/teal.modules.clinical/pull/835 https://github.com/insightsengineering/teal.modules.hermes/pull/336 https://github.com/insightsengineering/teal.osprey/pull/229 https://github.com/insightsengineering/teal.goshawk/pull/241 ref issues and discussion: https://github.com/insightsengineering/teal.reporter/issues/226 --------- Signed-off-by: kartikeya kirar Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com> Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> --- NAMESPACE | 1 + R/utils.R | 31 +++++++++++++++++++++++++++++++ _pkgdown.yml | 1 + man/report_card_template.Rd | 33 +++++++++++++++++++++++++++++++++ tests/testthat/test-utils.R | 26 ++++++++++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 man/report_card_template.Rd diff --git a/NAMESPACE b/NAMESPACE index 4711ead7a4..fbf4258c0c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,6 +27,7 @@ export(init) export(module) export(modules) export(new_tdata) +export(report_card_template) export(reporter_previewer_module) export(show_rcode_modal) export(srv_teal_with_splash) diff --git a/R/utils.R b/R/utils.R index 9d284e5054..dffa06364a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -46,3 +46,34 @@ include_parent_datanames <- function(dataname, join_keys) { return(unique(c(parents, dataname))) } + +#' Template Function for `TealReportCard` Creation and Customization +#' +#' This function generates a report card with a title, +#' an optional description, and the option to append the filter state list. +#' +#' @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 +#' +#' @export +report_card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { + checkmate::assert_string(title) + checkmate::assert_string(label) + checkmate::assert_string(description, null.ok = TRUE) + checkmate::assert_flag(with_filter) + checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") + + 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/_pkgdown.yml b/_pkgdown.yml index e0752c788e..9525fbdd7a 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -106,6 +106,7 @@ reference: contents: - reporter_previewer_module - TealReportCard + - report_card_template - title: Functions for Module Developers contents: - tdata diff --git a/man/report_card_template.Rd b/man/report_card_template.Rd new file mode 100644 index 0000000000..1be43cf829 --- /dev/null +++ b/man/report_card_template.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{report_card_template} +\alias{report_card_template} +\title{Template Function for \code{TealReportCard} Creation and Customization} +\usage{ +report_card_template( + title, + label, + description = NULL, + with_filter, + filter_panel_api +) +} +\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{ +This function generates a report card with a title, +an optional description, and the option to append the filter state list. +} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 319dfe302b..e64f4265cf 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -10,3 +10,29 @@ testthat::test_that("get_teal_bs_theme", { testthat::expect_warning(get_teal_bs_theme(), "the default shiny bootstrap is used") }) }) + +testthat::test_that("report_card_template function returns TealReportCard object with appropriate content and labels", { + fd <- teal.slice::init_filtered_data(list(iris = list(dataset = iris))) + filter_panel_api <- teal.slice::FilterPanelAPI$new(fd) + + card <- shiny::isolate(report_card_template( + title = "Card title", + label = "Card label", + description = "Sample description", + with_filter = TRUE, + filter_panel_api = filter_panel_api + )) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card label") + testthat::expect_length(card$get_content(), 4) + + card <- shiny::isolate(report_card_template( + title = "Card title", + label = "", + with_filter = FALSE, + filter_panel_api = filter_panel_api + )) + testthat::expect_s3_class(card, c("TealReportCard")) + testthat::expect_equal(card$get_name(), "Card title") + testthat::expect_length(card$get_content(), 1) +}) From ebbf7a619a8ba6499f5593eaae773ff8f1775c7f Mon Sep 17 00:00:00 2001 From: kartikeyakirar Date: Fri, 13 Oct 2023 09:46:18 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 0.14.0.9012 --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0930538a7c..95328de84b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: teal Title: Exploratory Web Apps for Analyzing Clinical Trials Data -Version: 0.14.0.9011 -Date: 2023-10-12 +Version: 0.14.0.9012 +Date: 2023-10-13 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre")), person("Pawel", "Rucki", , "pawel.rucki@roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index a22243fc1e..55545d90bf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal 0.14.0.9011 +# teal 0.14.0.9012 ### Miscellaneous