From 629f98168c5baf9c2bacfb0d395f4a8c2ef32d97 Mon Sep 17 00:00:00 2001 From: Marcin <133694481+m7pr@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:52:37 +0200 Subject: [PATCH 1/2] 198 Include user's card labels when generating the report (#219) Closes #198 and accompanied by https://github.com/insightsengineering/teal.modules.clinical/pull/835 # The problem Currently most of the `teal` modules, that wrap up `teal.reporter` in their UI, have titles of the `ReportCard` hardcoded in their body. For example check out below 2 modules https://github.com/insightsengineering/teal.modules.clinical/blob/2b20a85b22f25f15f6808f745b4d1d5333b123f3/R/tm_g_ci.R#L484-L503 https://github.com/insightsengineering/teal.modules.clinical/blob/2b20a85b22f25f15f6808f745b4d1d5333b123f3/R/tm_g_km.R#L774-L793 Such hardcoded content in `card$set_name()` and `card$append_text()` has a great impact on the final `ReportCard`. If `label` in the `Add Card` module UI is not provided, then the card name is set to the one passed in `card$set_name()`. This is fine for cards that had empty labels - they will have a name populated by the developer of the teal module. ![image](https://github.com/insightsengineering/teal.reporter/assets/133694481/b5d3656b-b61f-450f-ba69-b9db14889a24) However `card$append_text()` like this https://github.com/insightsengineering/teal.modules.clinical/blob/2b20a85b22f25f15f6808f745b4d1d5333b123f3/R/tm_g_km.R#L778 and this https://github.com/insightsengineering/teal.modules.clinical/blob/2b20a85b22f25f15f6808f745b4d1d5333b123f3/R/tm_g_ci.R#L489 appends a content to the card. The card gets a hardcoded title, no matter what user specifies as a card label. # The solution `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization. This means, that you are able to use `label` shiny input and use it in your `card_fun` to pass the title. We are able to rewrite teal modules, so that they have default titles, if `label` is empty in `Add Card` module UI. When it is not empty, then the `label` is used as a name and as a title of the card - like in this commit https://github.com/insightsengineering/teal.modules.clinical/commit/5833c6c7f52aecac8da09b16da31e73fe5dffe07 ## With label ![image](https://github.com/insightsengineering/teal.reporter/assets/133694481/2c96ba72-19eb-41c8-82a6-bd89bcaa02cc) ![image](https://github.com/insightsengineering/teal.reporter/assets/133694481/5ab17ab9-e2a9-40fc-96ee-068be0c34b42) ## Without the label ![image](https://github.com/insightsengineering/teal.reporter/assets/133694481/c318d90b-4518-4839-bf5a-5189e771c6bb) **so the default `teal` module name and title are used** ![image](https://github.com/insightsengineering/teal.reporter/assets/133694481/7c313c1c-adf6-4cdd-afba-d23791144dbd) --------- Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com> Co-authored-by: kartikeya kirar Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Dony Unardi --- NEWS.md | 4 ++++ R/AddCardModule.R | 22 +++++++++++++--------- man/add_card_button_srv.Rd | 13 +++++++------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/NEWS.md b/NEWS.md index f79730a6..0ceeedee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # teal.reporter 0.2.1.9005 +* `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization. + # teal.reporter 0.2.1 ### Miscellaneous @@ -9,6 +11,8 @@ * Fixed CRAN requirements for the first CRAN submission. * Removed manual pages for non-exported objects. +* Fixed CRAN requirements for the first CRAN submission. + # teal.reporter 0.2.0 ### New features diff --git a/R/AddCardModule.R b/R/AddCardModule.R index d9f639a3..7d050d5e 100644 --- a/R/AddCardModule.R +++ b/R/AddCardModule.R @@ -70,20 +70,20 @@ add_card_button_ui <- function(id) { #' #' @param id `character(1)` this `shiny` module's id. #' @param reporter [`Reporter`] instance. -#' @param card_fun `function` which returns a [`ReportCard`] instance, -#' the function has optional `card` and `comment` arguments. -#' If the `card` argument is added then the `ReportCard` instance is automatically created for the user. -#' If the `comment` argument is not specified then it is added automatically at the end of the Card. -#' The card name set by default in `card_fun` will be overcome by the `label` input which will be set automatically -#' when adding a card. -#' +#' @param card_fun `function` which returns a [`ReportCard`] instance. It can have optional `card`, `comment` and +#' `label` parameters. If `card` parameter is added, then the `ReportCard` instance is created for the user. +#' Use `comment` parameter to pass it's value whenever you prefer with `card$append_text()` - if `card_fun` does not +#' have `comment` parameter, then `comment` from `Add Card UI` module will be added at the end of the content of the +#' card. If `label` parameter is provided, you can use it to customize appearance of the `card name` and use if to +#' specify `card` content with `card$append_text()` - if `card_fun` does not have `label` parameter, then `card name` +#' will be set to the name passed in `Add Card UI` module, but no text will be added to the content of the `card`. #' #' @return `shiny::moduleServer` #' @export add_card_button_srv <- function(id, reporter, card_fun) { checkmate::assert_function(card_fun) checkmate::assert_class(reporter, "Reporter") - checkmate::assert_subset(names(formals(card_fun)), c("card", "comment"), empty.ok = TRUE) + checkmate::assert_subset(names(formals(card_fun)), c("card", "comment", "label"), empty.ok = TRUE) shiny::moduleServer( id, @@ -151,12 +151,16 @@ add_card_button_srv <- function(id, reporter, card_fun) { card_fun_args_nams <- names(formals(card_fun)) has_card_arg <- "card" %in% card_fun_args_nams has_comment_arg <- "comment" %in% card_fun_args_nams + has_label_arg <- "label" %in% card_fun_args_nams arg_list <- list() if (has_comment_arg) { arg_list <- c(arg_list, list(comment = input$comment)) } + if (has_label_arg) { + arg_list <- c(arg_list, list(label = input$label)) + } if (has_card_arg) { # The default_card is defined here because formals() returns a pairedlist object @@ -191,7 +195,7 @@ add_card_button_srv <- function(id, reporter, card_fun) { card$append_text(input$comment) } - if (length(input$label) == 1 && input$label != "") { + if (!has_label_arg && length(input$label) == 1 && input$label != "") { card$set_name(input$label) } diff --git a/man/add_card_button_srv.Rd b/man/add_card_button_srv.Rd index 0e8b0253..07e98e2d 100644 --- a/man/add_card_button_srv.Rd +++ b/man/add_card_button_srv.Rd @@ -11,12 +11,13 @@ add_card_button_srv(id, reporter, card_fun) \item{reporter}{\code{\link{Reporter}} instance.} -\item{card_fun}{\code{function} which returns a \code{\link{ReportCard}} instance, -the function has optional \code{card} and \code{comment} arguments. -If the \code{card} argument is added then the \code{ReportCard} instance is automatically created for the user. -If the \code{comment} argument is not specified then it is added automatically at the end of the Card. -The card name set by default in \code{card_fun} will be overcome by the \code{label} input which will be set automatically -when adding a card.} +\item{card_fun}{\code{function} which returns a \code{\link{ReportCard}} instance. It can have optional \code{card}, \code{comment} and +\code{label} parameters. If \code{card} parameter is added, then the \code{ReportCard} instance is created for the user. +Use \code{comment} parameter to pass it's value whenever you prefer with \code{card$append_text()} - if \code{card_fun} does not +have \code{comment} parameter, then \code{comment} from \verb{Add Card UI} module will be added at the end of the content of the +card. If \code{label} parameter is provided, you can use it to customize appearance of the \verb{card name} and use if to +specify \code{card} content with \code{card$append_text()} - if \code{card_fun} does not have \code{label} parameter, then \verb{card name} +will be set to the name passed in \verb{Add Card UI} module, but no text will be added to the content of the \code{card}.} } \value{ \code{shiny::moduleServer} From b82c2acb63cf2ef80e1009bdc030c8bafce91bfe Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 3 Oct 2023 08:53:43 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 0.2.1.9006 --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2a1e77c2..99ec742e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: teal.reporter Title: Reporting Tools for 'shiny' Modules -Version: 0.2.1.9005 -Date: 2023-09-29 +Version: 0.2.1.9006 +Date: 2023-10-03 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = "cre"), person("Maciej", "Nasinski", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 0ceeedee..a210d1ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal.reporter 0.2.1.9005 +# teal.reporter 0.2.1.9006 * `add_card_button_srv` allows to specify `card_fun` with `label` parameter for card's title & content customization.