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 Include user's card labels when generating the report #336

Merged
merged 12 commits into from
Oct 13, 2023
11 changes: 6 additions & 5 deletions R/barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,12 @@ srv_g_barplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Barplot")
card$append_text("Barplot", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Barplot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
11 changes: 6 additions & 5 deletions R/boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ srv_g_boxplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Boxplot")
card$append_text("Boxplot", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Boxplot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
11 changes: 6 additions & 5 deletions R/forestplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,12 @@ srv_g_forest_tte <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Forest Plot")
card$append_text("Forest Plot", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Forest Plot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
11 changes: 6 additions & 5 deletions R/km.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,12 @@ srv_g_km <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Kaplan-Meier Plot")
card$append_text("Kaplan-Meier Plot", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Kaplan-Meier Plot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
11 changes: 6 additions & 5 deletions R/pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,12 @@ srv_g_pca <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("PCA")
card$append_text("PCA", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "PCA",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
if (input$tab_selected == "PCA") {
encodings_list <- list(
Expand Down
13 changes: 7 additions & 6 deletions R/quality.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,13 @@ srv_g_quality <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Quality Control Plot")
card$append_text("Quality Control Plot", "header2")
card$append_text(tools::toTitleCase(input$plot_type), "header3")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Quality Control Plot",
label = label,
description = tools::toTitleCase(input$plot_type),
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
11 changes: 6 additions & 5 deletions R/scatterplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,12 @@ 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")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Scatter Plot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
27 changes: 27 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,30 @@ include_js_files <- function(pattern = "*") { # nolint
)
return(singleton(lapply(js_files, includeScript)))
}

#' Template function to generate reporter card for `teal.modules.hermes`
#' @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 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, filter_panel_api) {
checkmate::assert_string(title)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry can we please take out the checkmate:: name space thing since we import the whole of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

putting package name in front of package function improves the process of debugging if you debug the function interactively

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teal is also imported as a whole but we do put :: in front of teal function names https://github.com/search?q=repo%3Ainsightsengineering%2Fteal.modules.hermes%20%3A%3A&type=code

teal::module(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we should also take out the teal:: bits please. thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kartikeyakirar have you seen this conversation about teal

Copy link
Contributor Author

@kartikeyakirar kartikeyakirar Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I will take out teal:: call as well.

Edit : Namespace calls are throughout the package, and it's not within the scope of this task to eliminate all of them. However, I will remove teal::report_card_template. As for the rest, I will put the task to handle them separately .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is task : #337

checkmate::assert_string(label)
checkmate::assert_string(description, null.ok = TRUE)
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")
}
card$append_fs(filter_panel_api$get_filter_state())
card
}
11 changes: 6 additions & 5 deletions R/volcanoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ srv_g_volcanoplot <- function(id,

### REPORTER
if (with_reporter) {
card_fun <- function(comment) {
card <- teal::TealReportCard$new()
card$set_name("Volcano Plot")
card$append_text("Volcano Plot", "header2")
card$append_fs(filter_panel_api$get_filter_state())
card_fun <- function(comment, label) {
card <- card_template(
title = "Volcano Plot",
label = label,
filter_panel_api = filter_panel_api
)
card$append_text("Selected Options", "header3")
encodings_list <- list(
"Experiment:",
Expand Down
25 changes: 25 additions & 0 deletions man/card_template.Rd

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

25 changes: 25 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,28 @@ test_that("h_extract_words works as expected", {
"All elements must have at least 1 characters, but element 1 has 0 characters."
)
})

testthat::test_that("card_template function returns TealReportCard object with appropriate content and labels", {
danielinteractive marked this conversation as resolved.
Show resolved Hide resolved
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 = NULL,
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(), 3)

card <- shiny::isolate(card_template(
title = "Card title",
label = "",
description = "Description text",
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(), 4)
})