Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

198 extension to Include user's card labels when generating the report #223

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Suggests:
lattice (>= 0.18-4),
png,
rtables (>= 0.5.1),
teal (>= 0.14.0),
teal.slice (>= 0.4.0),
testthat (>= 3.0.4),
tinytex
VignetteBuilder:
Expand All @@ -47,7 +49,8 @@ Config/Needs/verdepcheck: rstudio/bslib, mllg/checkmate,
rstudio/rmarkdown, rstudio/shiny, dreamRs/shinyWidgets,
yaml=vubiostat/r-yaml, r-lib/zip, davidgohel/flextable, rstudio/DT,
yihui/formatR, tidyverse/ggplot2, deepayan/lattice, cran/png,
insightsengineering/rtables, r-lib/testthat, rstudio/tinytex
insightsengineering/rtables, insightsengineering/teal,
insightsengineering/teal.slice, r-lib/testthat, rstudio/tinytex
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
Language: en-US
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(Reporter)
export(add_card_button_srv)
export(add_card_button_ui)
export(as_yaml_auto)
export(card_template)
export(download_report_button_srv)
export(download_report_button_ui)
export(reporter_previewer_srv)
Expand Down
35 changes: 35 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,38 @@ global_knitr_details <- function() {
collapse = "\n"
)
}

#' Template function to generate reporter card.
#'
#' 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
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
}
27 changes: 27 additions & 0 deletions man/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 @@ -65,3 +65,29 @@ testthat::test_that("split_text_block - splits text block into blocks no longer
result <- split_text_block(block_text, n)
testthat::expect_equal(result, list(block_text))
})

testthat::test_that("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(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(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)
})
Loading