Skip to content

Commit

Permalink
198 extension to Include user's card labels when generating the report (
Browse files Browse the repository at this point in the history
#933)

this PR is extension to
insightsengineering/teal.reporter#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
insightsengineering/teal.modules.general#584
insightsengineering/teal.modules.clinical#835
insightsengineering/teal.modules.hermes#336
insightsengineering/teal.osprey#229
insightsengineering/teal.goshawk#241

ref issues and discussion:
insightsengineering/teal.reporter#226

---------

Signed-off-by: kartikeya kirar <[email protected]>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Marcin <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 13, 2023
1 parent e722c60 commit 57fdce9
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ reference:
contents:
- reporter_previewer_module
- TealReportCard
- report_card_template
- title: Functions for Module Developers
contents:
- tdata
Expand Down
33 changes: 33 additions & 0 deletions man/report_card_template.Rd

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

26 changes: 26 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 57fdce9

Please sign in to comment.