From 7239549e44f89c259c1d6d85782ba09ebf40adaf Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Oct 2023 18:33:49 +0530 Subject: [PATCH 01/11] add card_template function and allow to pass label to reporter card content --- R/barplot.R | 13 ++++++++----- R/boxplot.R | 13 ++++++++----- R/forestplot.R | 13 ++++++++----- R/km.R | 13 ++++++++----- R/pca.R | 13 ++++++++----- R/quality.R | 14 ++++++++------ R/scatterplot.R | 13 ++++++++----- R/utils.R | 25 +++++++++++++++++++++++++ R/volcanoplot.R | 13 ++++++++----- 9 files changed, 89 insertions(+), 41 deletions(-) diff --git a/R/barplot.R b/R/barplot.R index d1bd936f..33342807 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -190,11 +190,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/boxplot.R b/R/boxplot.R index 8ef19d36..8db0f65e 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -185,11 +185,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/forestplot.R b/R/forestplot.R index 40fb4cca..19315ba5 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -230,11 +230,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/km.R b/R/km.R index 87fce4c3..321d216b 100644 --- a/R/km.R +++ b/R/km.R @@ -222,11 +222,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/pca.R b/R/pca.R index 234537fd..f0488f37 100644 --- a/R/pca.R +++ b/R/pca.R @@ -357,11 +357,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") if (input$tab_selected == "PCA") { encodings_list <- list( diff --git a/R/quality.R b/R/quality.R index 6dc6dda9..679b2176 100644 --- a/R/quality.R +++ b/R/quality.R @@ -353,12 +353,14 @@ 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), + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/scatterplot.R b/R/scatterplot.R index 5a00914d..1ec6d746 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -185,11 +185,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", diff --git a/R/utils.R b/R/utils.R index 8d04080e..c484146c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -77,3 +77,28 @@ 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 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 +#' +#' @keywords internal +card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { + 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/R/volcanoplot.R b/R/volcanoplot.R index db1a3842..e283b681 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -207,11 +207,14 @@ 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, + description = NULL, + with_filter = TRUE, + filter_panel_api = filter_panel_api + ) card$append_text("Selected Options", "header3") encodings_list <- list( "Experiment:", From b1f8bef40db225f981a603a29d28828bc520f4f8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 4 Oct 2023 18:35:13 +0530 Subject: [PATCH 02/11] adding Rd file --- man/card_template.Rd | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 man/card_template.Rd diff --git a/man/card_template.Rd b/man/card_template.Rd new file mode 100644 index 00000000..1627ac17 --- /dev/null +++ b/man/card_template.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{card_template} +\alias{card_template} +\title{Template function to generate reporter card for \code{teal.modules.hermes}} +\usage{ +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{ +Template function to generate reporter card for \code{teal.modules.hermes} +} +\keyword{internal} From 9ada482e2e2b0d88f5fcd56a291deb46f52c475d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Oct 2023 17:14:31 +0530 Subject: [PATCH 03/11] Adding unit-test and removing default parameter defined in function call. --- R/boxplot.R | 2 -- R/forestplot.R | 2 -- R/km.R | 2 -- R/pca.R | 2 -- R/quality.R | 1 - R/scatterplot.R | 2 -- R/utils.R | 12 +++++++----- R/volcanoplot.R | 2 -- man/card_template.Rd | 4 +--- tests/testthat/test-utils.R | 22 ++++++++++++++++++++++ 10 files changed, 30 insertions(+), 21 deletions(-) diff --git a/R/boxplot.R b/R/boxplot.R index 8db0f65e..2f931e0f 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -189,8 +189,6 @@ srv_g_boxplot <- function(id, card <- card_template( title = "Boxplot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/forestplot.R b/R/forestplot.R index 19315ba5..2647aa67 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -234,8 +234,6 @@ srv_g_forest_tte <- function(id, card <- card_template( title = "Forest Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/km.R b/R/km.R index 321d216b..f3dd69c7 100644 --- a/R/km.R +++ b/R/km.R @@ -226,8 +226,6 @@ srv_g_km <- function(id, card <- card_template( title = "Kaplan-Meier Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/pca.R b/R/pca.R index f0488f37..76c809cb 100644 --- a/R/pca.R +++ b/R/pca.R @@ -361,8 +361,6 @@ srv_g_pca <- function(id, card <- card_template( title = "PCA", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/quality.R b/R/quality.R index 679b2176..4caedc93 100644 --- a/R/quality.R +++ b/R/quality.R @@ -358,7 +358,6 @@ srv_g_quality <- function(id, title = "Quality Control Plot", label = label, description = tools::toTitleCase(input$plot_type), - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/scatterplot.R b/R/scatterplot.R index 1ec6d746..c46c805f 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -189,8 +189,6 @@ srv_g_scatterplot <- function(id, card <- card_template( title = "Scatter Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/utils.R b/R/utils.R index c484146c..1573a876 100644 --- a/R/utils.R +++ b/R/utils.R @@ -82,14 +82,18 @@ include_js_files <- function(pattern = "*") { # nolint #' @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 #' #' @keywords internal -card_template <- function(title, label, description = NULL, with_filter, filter_panel_api) { +card_template <- function(title, label, description = NULL, filter_panel_api) { + checkmate::assert_string(title) + 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) @@ -97,8 +101,6 @@ card_template <- function(title, label, description = NULL, with_filter, filter_ if (!is.null(description)) { card$append_text(description, "header3") } - if (with_filter) { - card$append_fs(filter_panel_api$get_filter_state()) - } + card$append_fs(filter_panel_api$get_filter_state()) card } diff --git a/R/volcanoplot.R b/R/volcanoplot.R index e283b681..9b53c0ca 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -211,8 +211,6 @@ srv_g_volcanoplot <- function(id, card <- card_template( title = "Volcano Plot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/man/card_template.Rd b/man/card_template.Rd index 1627ac17..89769c62 100644 --- a/man/card_template.Rd +++ b/man/card_template.Rd @@ -4,7 +4,7 @@ \alias{card_template} \title{Template function to generate reporter card for \code{teal.modules.hermes}} \usage{ -card_template(title, label, description = NULL, with_filter, filter_panel_api) +card_template(title, label, description = NULL, filter_panel_api) } \arguments{ \item{title}{(\code{character(1)}) title of the card (unless overwritten by label)} @@ -13,8 +13,6 @@ card_template(title, label, description = NULL, with_filter, filter_panel_api) \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} } diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 951f1c4a..bc53fe47 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -18,3 +18,25 @@ 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", { + 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) +}) + From e04793a95ace06fc6acabc30cbec451057519020 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Oct 2023 17:17:27 +0530 Subject: [PATCH 04/11] fixing lintr --- tests/testthat/test-utils.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index bc53fe47..6d68faf8 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -39,4 +39,3 @@ testthat::test_that("card_template function returns TealReportCard object with a testthat::expect_equal(card$get_name(), "Card title") testthat::expect_length(card$get_content(), 4) }) - From b577b49b5d0896c14dc75d12af5f0d99e0af56bc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 5 Oct 2023 17:19:08 +0530 Subject: [PATCH 05/11] removing default values from card_template in barplot. --- R/barplot.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/barplot.R b/R/barplot.R index 33342807..3b9a4295 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -194,8 +194,6 @@ srv_g_barplot <- function(id, card <- card_template( title = "Barplot", label = label, - description = NULL, - with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") From 3f050d37c31b5861fc4c5864bbf17d246653cbe2 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 11:52:36 +0000 Subject: [PATCH 06/11] [skip actions] Restyle files --- R/utils.R | 2 +- tests/testthat/test-utils.R | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/R/utils.R b/R/utils.R index 1573a876..8f801b74 100644 --- a/R/utils.R +++ b/R/utils.R @@ -92,7 +92,7 @@ card_template <- function(title, label, description = NULL, filter_panel_api) { checkmate::assert_string(title) checkmate::assert_string(label) checkmate::assert_string(description, null.ok = TRUE) - checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") + checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") card <- teal::TealReportCard$new() title <- if (label == "") title else label diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 6d68faf8..9fb588d4 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -23,18 +23,22 @@ testthat::test_that("card_template function returns TealReportCard object with a 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)) + 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)) + 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) From 3bd4c233eb5abad53fb502676ec282df46e3e364 Mon Sep 17 00:00:00 2001 From: kartikeyakirar Date: Thu, 5 Oct 2023 17:25:13 +0530 Subject: [PATCH 07/11] 'Empty-Commit' From 0bac7e4973c36956328a00019ae3a1f416f380cc Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Oct 2023 13:28:51 +0530 Subject: [PATCH 08/11] removing namespace call --- R/utils.R | 8 ++++---- tests/testthat/test-utils.R | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/R/utils.R b/R/utils.R index 8f801b74..dc4f76cf 100644 --- a/R/utils.R +++ b/R/utils.R @@ -89,10 +89,10 @@ include_js_files <- function(pattern = "*") { # nolint #' #' @keywords internal card_template <- function(title, label, description = NULL, filter_panel_api) { - checkmate::assert_string(title) - checkmate::assert_string(label) - checkmate::assert_string(description, null.ok = TRUE) - checkmate::assert_class(filter_panel_api, classes = "FilterPanelAPI") + assert_string(title) + assert_string(label) + assert_string(description, null.ok = TRUE) + assert_class(filter_panel_api, classes = "FilterPanelAPI") card <- teal::TealReportCard$new() title <- if (label == "") title else label diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 9fb588d4..9c75ca1f 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -19,7 +19,7 @@ test_that("h_extract_words works as expected", { ) }) -testthat::test_that("card_template function returns TealReportCard object with appropriate content and labels", { +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) @@ -29,9 +29,9 @@ testthat::test_that("card_template function returns TealReportCard object with a 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) + expect_s3_class(card, c("TealReportCard")) + expect_equal(card$get_name(), "Card label") + expect_length(card$get_content(), 3) card <- shiny::isolate(card_template( title = "Card title", @@ -39,7 +39,7 @@ testthat::test_that("card_template function returns TealReportCard object with a 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) + expect_s3_class(card, c("TealReportCard")) + expect_equal(card$get_name(), "Card title") + expect_length(card$get_content(), 4) }) From f7f724025ff5e20e99c6bea59620122b81a5dce3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Oct 2023 14:08:36 +0530 Subject: [PATCH 09/11] removing card_template function and unit-test --- R/barplot.R | 3 ++- R/boxplot.R | 3 ++- R/forestplot.R | 3 ++- R/km.R | 3 ++- R/pca.R | 3 ++- R/quality.R | 3 ++- R/scatterplot.R | 3 ++- R/utils.R | 27 --------------------------- R/volcanoplot.R | 3 ++- man/card_template.Rd | 25 ------------------------- tests/testthat/test-utils.R | 25 ------------------------- 11 files changed, 16 insertions(+), 85 deletions(-) delete mode 100644 man/card_template.Rd diff --git a/R/barplot.R b/R/barplot.R index 3b9a4295..ec16349c 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -191,9 +191,10 @@ srv_g_barplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Barplot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/boxplot.R b/R/boxplot.R index 2f931e0f..bf335f50 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -186,9 +186,10 @@ srv_g_boxplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Boxplot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/forestplot.R b/R/forestplot.R index 2647aa67..bebebc5b 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -231,9 +231,10 @@ srv_g_forest_tte <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Forest Plot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/km.R b/R/km.R index f3dd69c7..d60a688e 100644 --- a/R/km.R +++ b/R/km.R @@ -223,9 +223,10 @@ srv_g_km <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Kaplan-Meier Plot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/pca.R b/R/pca.R index 76c809cb..241a1816 100644 --- a/R/pca.R +++ b/R/pca.R @@ -358,9 +358,10 @@ srv_g_pca <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "PCA", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/quality.R b/R/quality.R index 4caedc93..34a53460 100644 --- a/R/quality.R +++ b/R/quality.R @@ -354,10 +354,11 @@ srv_g_quality <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Quality Control Plot", label = label, description = tools::toTitleCase(input$plot_type), + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/scatterplot.R b/R/scatterplot.R index c46c805f..f88f83ca 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -186,9 +186,10 @@ srv_g_scatterplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Scatter Plot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/R/utils.R b/R/utils.R index dc4f76cf..8d04080e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -77,30 +77,3 @@ 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) { - assert_string(title) - assert_string(label) - assert_string(description, null.ok = TRUE) - 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 -} diff --git a/R/volcanoplot.R b/R/volcanoplot.R index 9b53c0ca..6d956e1c 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -208,9 +208,10 @@ srv_g_volcanoplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- card_template( + card <- teal.reporter::card_template( title = "Volcano Plot", label = label, + with_filter = TRUE, filter_panel_api = filter_panel_api ) card$append_text("Selected Options", "header3") diff --git a/man/card_template.Rd b/man/card_template.Rd deleted file mode 100644 index 89769c62..00000000 --- a/man/card_template.Rd +++ /dev/null @@ -1,25 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{card_template} -\alias{card_template} -\title{Template function to generate reporter card for \code{teal.modules.hermes}} -\usage{ -card_template(title, label, description = NULL, 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{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{ -Template function to generate reporter card for \code{teal.modules.hermes} -} -\keyword{internal} diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 9c75ca1f..951f1c4a 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -18,28 +18,3 @@ test_that("h_extract_words works as expected", { "All elements must have at least 1 characters, but element 1 has 0 characters." ) }) - -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 = NULL, - filter_panel_api = filter_panel_api - )) - expect_s3_class(card, c("TealReportCard")) - expect_equal(card$get_name(), "Card label") - expect_length(card$get_content(), 3) - - card <- shiny::isolate(card_template( - title = "Card title", - label = "", - description = "Description text", - filter_panel_api = filter_panel_api - )) - expect_s3_class(card, c("TealReportCard")) - expect_equal(card$get_name(), "Card title") - expect_length(card$get_content(), 4) -}) From 0fbb71f038b92a0fd9d1b0da718b024db613ba4e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Oct 2023 15:22:09 +0530 Subject: [PATCH 10/11] renaming to report_card_template --- R/barplot.R | 2 +- R/boxplot.R | 2 +- R/forestplot.R | 2 +- R/km.R | 2 +- R/pca.R | 2 +- R/quality.R | 2 +- R/scatterplot.R | 2 +- R/volcanoplot.R | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/barplot.R b/R/barplot.R index ec16349c..746b835d 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -191,7 +191,7 @@ srv_g_barplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Barplot", label = label, with_filter = TRUE, diff --git a/R/boxplot.R b/R/boxplot.R index bf335f50..27d0a91a 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -186,7 +186,7 @@ srv_g_boxplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Boxplot", label = label, with_filter = TRUE, diff --git a/R/forestplot.R b/R/forestplot.R index bebebc5b..c8bb834d 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -231,7 +231,7 @@ srv_g_forest_tte <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Forest Plot", label = label, with_filter = TRUE, diff --git a/R/km.R b/R/km.R index d60a688e..298e2e38 100644 --- a/R/km.R +++ b/R/km.R @@ -223,7 +223,7 @@ srv_g_km <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Kaplan-Meier Plot", label = label, with_filter = TRUE, diff --git a/R/pca.R b/R/pca.R index 241a1816..3e00a13d 100644 --- a/R/pca.R +++ b/R/pca.R @@ -358,7 +358,7 @@ srv_g_pca <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "PCA", label = label, with_filter = TRUE, diff --git a/R/quality.R b/R/quality.R index 34a53460..88617a7f 100644 --- a/R/quality.R +++ b/R/quality.R @@ -354,7 +354,7 @@ srv_g_quality <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Quality Control Plot", label = label, description = tools::toTitleCase(input$plot_type), diff --git a/R/scatterplot.R b/R/scatterplot.R index f88f83ca..b5f96bac 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -186,7 +186,7 @@ srv_g_scatterplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Scatter Plot", label = label, with_filter = TRUE, diff --git a/R/volcanoplot.R b/R/volcanoplot.R index 6d956e1c..3fe35ab0 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -208,7 +208,7 @@ srv_g_volcanoplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal.reporter::card_template( + card <- teal::report_card_template( title = "Volcano Plot", label = label, with_filter = TRUE, From 068f65a41106dae6dbdd43638ad0a25cbd27c31e Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Oct 2023 22:39:09 +0530 Subject: [PATCH 11/11] removing namespace call --- R/barplot.R | 2 +- R/boxplot.R | 2 +- R/forestplot.R | 2 +- R/km.R | 2 +- R/pca.R | 2 +- R/quality.R | 2 +- R/scatterplot.R | 2 +- R/volcanoplot.R | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/barplot.R b/R/barplot.R index 746b835d..02b92944 100644 --- a/R/barplot.R +++ b/R/barplot.R @@ -191,7 +191,7 @@ srv_g_barplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Barplot", label = label, with_filter = TRUE, diff --git a/R/boxplot.R b/R/boxplot.R index 27d0a91a..cbc8e397 100644 --- a/R/boxplot.R +++ b/R/boxplot.R @@ -186,7 +186,7 @@ srv_g_boxplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Boxplot", label = label, with_filter = TRUE, diff --git a/R/forestplot.R b/R/forestplot.R index c8bb834d..d4cda342 100644 --- a/R/forestplot.R +++ b/R/forestplot.R @@ -231,7 +231,7 @@ srv_g_forest_tte <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Forest Plot", label = label, with_filter = TRUE, diff --git a/R/km.R b/R/km.R index 298e2e38..23de5f87 100644 --- a/R/km.R +++ b/R/km.R @@ -223,7 +223,7 @@ srv_g_km <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Kaplan-Meier Plot", label = label, with_filter = TRUE, diff --git a/R/pca.R b/R/pca.R index 3e00a13d..fb1dbcfa 100644 --- a/R/pca.R +++ b/R/pca.R @@ -358,7 +358,7 @@ srv_g_pca <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "PCA", label = label, with_filter = TRUE, diff --git a/R/quality.R b/R/quality.R index 88617a7f..31c32624 100644 --- a/R/quality.R +++ b/R/quality.R @@ -354,7 +354,7 @@ srv_g_quality <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Quality Control Plot", label = label, description = tools::toTitleCase(input$plot_type), diff --git a/R/scatterplot.R b/R/scatterplot.R index b5f96bac..0ea51c93 100644 --- a/R/scatterplot.R +++ b/R/scatterplot.R @@ -186,7 +186,7 @@ srv_g_scatterplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Scatter Plot", label = label, with_filter = TRUE, diff --git a/R/volcanoplot.R b/R/volcanoplot.R index 3fe35ab0..6b316b4e 100644 --- a/R/volcanoplot.R +++ b/R/volcanoplot.R @@ -208,7 +208,7 @@ srv_g_volcanoplot <- function(id, ### REPORTER if (with_reporter) { card_fun <- function(comment, label) { - card <- teal::report_card_template( + card <- report_card_template( title = "Volcano Plot", label = label, with_filter = TRUE,