From 62fd70243fe7a15d1e75ab6f0aea34183808b87a Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Wed, 7 Jan 2026 05:44:56 -0500 Subject: [PATCH 01/11] Watermark decorator changes --- .gitignore | 2 + R/watermark_decorator.R | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 R/watermark_decorator.R diff --git a/.gitignore b/.gitignore index 7c7dbdd..c8ac899 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ *.Rcheck *.tar.gz +*.Rproj +.Rproj.user diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R new file mode 100644 index 0000000..e31dbaf --- /dev/null +++ b/R/watermark_decorator.R @@ -0,0 +1,99 @@ +#' Watermark Decorator +#' +#' @description `r lifecycle::badge("experimental")` +#' A function to create a UI component for selecting watermark text +#' for tables or plots. +#' @param output_name (`character(1)`) a name for the output object (e.g., a plot or table). +#' @param watermark_text (`character(1)`) text to display for the watermark +#' @param font_size (`character(1)`) font size for the watermark text +#' +#' @return [`teal::teal_transform_module()`] +#' +#' @details The module creates a UI with textInput for specifying watermark text and +#' font size. +#' the entered watermark text is displayed with a default gridify layout. +#' +#' @import cowplot gridify rtables.officer +#' @importFrom grDevices graphics.off +#' +#' @export +watermark_decorator <- function(output_name, watermark_text = "", font_size = 90) { + checkmate::assert_string(output_name) + checkmate::assert_string(watermark_text) + + teal::teal_transform_module( + label = "Watermark decorator", + ui = function(id) { + ns <- NS(id) + tagList( + div( + textInput(ns("txtWatermark"), label = "Enter Text", value = watermark_text), + numericInput(ns("numFontsize"), label = "Enter Font size", value = font_size) + ) + ) + }, + server = function(id, data) { + moduleServer(id, function(input, output, session) { + reactive({ + req(data()) + + res <- data() + # Determine the title and footer + res <- within( + res, + { + watermark_text <- txtWatermark + gridify_layout <- gridify::gridifyLayout( + nrow = 3L, + ncol = 1L, + heights = grid::unit(c(0.05, 0.9, 0.05), "npc"), + widths = grid::unit(1, "npc"), + margin = grid::unit(c(t = 0.1, r = 0.1, b = 0.1, l = 0.1), units = "cm"), + global_gpar = grid::gpar(), + background = grid::get.gpar()$fill, + adjust_height = FALSE, + object = gridifyObject(row = 2, col = 1), + cells = gridifyCells( + title = gridifyCell(row = 1, col = 1), + footer = gridifyCell(row = 3, col = 1), + watermark = gridifyCell(row = 1:3, col = 1, rot = 45, gpar = grid::gpar(fontsize = numFontsize, alpha = 0.3)) + ) + ) + }, + output_type = output_name, + output_name = as.name(output_name), + numFontsize = input$numFontsize, + txtWatermark = input$txtWatermark + ) + + if (output_name == "table") { + res <- within( + res, + { + output_name <- gridify::gridify( + object = rtables.officer::tt_to_flextable(output_name, theme = NULL), + layout = gridify_layout + ) %>% + set_cell("watermark", watermark_text) + + }, + output_name = as.name(output_name), + ) + } else { + res <- within( + res, + { + output_name <- gridify::gridify( + object = cowplot::as_grob(output_name), + layout = gridify_layout + ) %>% + set_cell("watermark", watermark_text) + }, + output_name = as.name(output_name) + ) + } + }) + }) + } + ) +} From 3f8f6c73f8a3708f2a04cef7295eb27f1b66f451 Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Wed, 21 Jan 2026 08:19:41 -0500 Subject: [PATCH 02/11] minor fixes and added documentation --- DESCRIPTION | 4 +++- NAMESPACE | 4 ++++ R/watermark_decorator.R | 2 +- man/watermark_decorator.Rd | 28 ++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 man/watermark_decorator.Rd diff --git a/DESCRIPTION b/DESCRIPTION index caacfb2..f6b7f86 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -44,7 +44,9 @@ Imports: teal, teal.code, tern, - yaml + yaml, + gridify, + rtables.officer Suggests: forcats, knitr, diff --git a/NAMESPACE b/NAMESPACE index a9995af..f83dc2e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,14 +11,18 @@ export(or_filtering_transformator) export(patchwork_plot_decorator) export(remove_by_label) export(title_footer_decorator) +export(watermark_decorator) import(checkmate) +import(cowplot) import(dplyr) import(ggplot2) import(ggplotify) +import(gridify) import(openxlsx) import(patchwork) import(rlang) import(rtables) +import(rtables.officer) import(shiny) import(shinyBS) import(shinyWidgets) diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R index e31dbaf..feb3d59 100644 --- a/R/watermark_decorator.R +++ b/R/watermark_decorator.R @@ -77,7 +77,7 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 set_cell("watermark", watermark_text) }, - output_name = as.name(output_name), + output_name = as.name(output_name) ) } else { res <- within( diff --git a/man/watermark_decorator.Rd b/man/watermark_decorator.Rd new file mode 100644 index 0000000..5ba2600 --- /dev/null +++ b/man/watermark_decorator.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/watermark_decorator.R +\name{watermark_decorator} +\alias{watermark_decorator} +\title{Watermark Decorator} +\usage{ +watermark_decorator(output_name, watermark_text = "", font_size = 90) +} +\arguments{ +\item{output_name}{(\code{character(1)}) a name for the output object (e.g., a plot or table).} + +\item{watermark_text}{(\code{character(1)}) text to display for the watermark} + +\item{font_size}{(\code{character(1)}) font size for the watermark text} +} +\value{ +\code{\link[teal:teal_transform_module]{teal::teal_transform_module()}} +} +\description{ +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} +A function to create a UI component for selecting watermark text +for tables or plots. +} +\details{ +The module creates a UI with textInput for specifying watermark text and +font size. +the entered watermark text is displayed with a default gridify layout. +} From 772782270347176de355ddd3ac4fb9a0be37ac01 Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Fri, 6 Feb 2026 09:09:29 -0500 Subject: [PATCH 03/11] Removed code for table is its not currently supported as required --- R/watermark_decorator.R | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R index feb3d59..71a414e 100644 --- a/R/watermark_decorator.R +++ b/R/watermark_decorator.R @@ -2,7 +2,8 @@ #' #' @description `r lifecycle::badge("experimental")` #' A function to create a UI component for selecting watermark text -#' for tables or plots. +#' for plots. +#' Note: Currently tables are not supported #' @param output_name (`character(1)`) a name for the output object (e.g., a plot or table). #' @param watermark_text (`character(1)`) text to display for the watermark #' @param font_size (`character(1)`) font size for the watermark text @@ -66,32 +67,18 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 txtWatermark = input$txtWatermark ) - if (output_name == "table") { - res <- within( - res, - { - output_name <- gridify::gridify( - object = rtables.officer::tt_to_flextable(output_name, theme = NULL), - layout = gridify_layout - ) %>% - set_cell("watermark", watermark_text) - - }, - output_name = as.name(output_name) - ) - } else { - res <- within( - res, - { - output_name <- gridify::gridify( - object = cowplot::as_grob(output_name), - layout = gridify_layout - ) %>% - set_cell("watermark", watermark_text) - }, - output_name = as.name(output_name) - ) - } + res <- within( + res, + { + output_name <- gridify::gridify( + object = cowplot::as_grob(output_name), + layout = gridify_layout + ) %>% + set_cell("watermark", watermark_text) + }, + output_name = as.name(output_name) + ) + }) }) } From 6e3e5b0f2c851863b72fb4a1bc9503f9d4687d01 Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Fri, 6 Feb 2026 09:13:46 -0500 Subject: [PATCH 04/11] Doc changes --- man/watermark_decorator.Rd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man/watermark_decorator.Rd b/man/watermark_decorator.Rd index 5ba2600..e658257 100644 --- a/man/watermark_decorator.Rd +++ b/man/watermark_decorator.Rd @@ -19,7 +19,8 @@ watermark_decorator(output_name, watermark_text = "", font_size = 90) \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} A function to create a UI component for selecting watermark text -for tables or plots. +for plots. +Note: Currently tables are not supported } \details{ The module creates a UI with textInput for specifying watermark text and From dac4079725a06178780186b1a153607098ad7254 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 07:04:46 +0000 Subject: [PATCH 05/11] [skip style] [skip vbump] Restyle files --- R/watermark_decorator.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R index 71a414e..6bcc165 100644 --- a/R/watermark_decorator.R +++ b/R/watermark_decorator.R @@ -2,7 +2,7 @@ #' #' @description `r lifecycle::badge("experimental")` #' A function to create a UI component for selecting watermark text -#' for plots. +#' for plots. #' Note: Currently tables are not supported #' @param output_name (`character(1)`) a name for the output object (e.g., a plot or table). #' @param watermark_text (`character(1)`) text to display for the watermark @@ -10,7 +10,7 @@ #' #' @return [`teal::teal_transform_module()`] #' -#' @details The module creates a UI with textInput for specifying watermark text and +#' @details The module creates a UI with textInput for specifying watermark text and #' font size. #' the entered watermark text is displayed with a default gridify layout. #' @@ -21,7 +21,7 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90) { checkmate::assert_string(output_name) checkmate::assert_string(watermark_text) - + teal::teal_transform_module( label = "Watermark decorator", ui = function(id) { @@ -37,7 +37,7 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 moduleServer(id, function(input, output, session) { reactive({ req(data()) - + res <- data() # Determine the title and footer res <- within( @@ -66,7 +66,7 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 numFontsize = input$numFontsize, txtWatermark = input$txtWatermark ) - + res <- within( res, { @@ -78,7 +78,6 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 }, output_name = as.name(output_name) ) - }) }) } From b52934f306dda29ce0e3c2e1e9ab18d8dd36acba Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Tue, 3 Mar 2026 02:17:56 -0500 Subject: [PATCH 06/11] NEWS entry added --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index a147d6e..d15050a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # Version 0.0.2.9000 - Refactored the `merge_levels_transformator` to handle the predefined inputs to the transformator([JGQO-323](https://jira.jnj.com/browse/JGQO-323)). +- Added new `watermark_decorator`.([#23](https://github.com/phuse-org/uteals/pull/23)) # Version 0.0.2 From 18ef14618058ca93d728b18e2cf7a461065954cf Mon Sep 17 00:00:00 2001 From: Nadia Abraham Date: Tue, 3 Mar 2026 05:28:43 -0500 Subject: [PATCH 07/11] Changes as per review feedback --- DESCRIPTION | 1 - NAMESPACE | 1 - R/watermark_decorator.R | 31 +++++++++++++++---------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9e27a60..9934666 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -47,7 +47,6 @@ Imports: tern, yaml, gridify, - rtables.officer teal.modules.clinical Suggests: forcats, diff --git a/NAMESPACE b/NAMESPACE index 6caf3e3..030ec6b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,7 +23,6 @@ import(openxlsx) import(patchwork) import(rlang) import(rtables) -import(rtables.officer) import(shiny) import(shinyBS) import(shinyWidgets) diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R index 6bcc165..b06d00d 100644 --- a/R/watermark_decorator.R +++ b/R/watermark_decorator.R @@ -5,16 +5,16 @@ #' for plots. #' Note: Currently tables are not supported #' @param output_name (`character(1)`) a name for the output object (e.g., a plot or table). -#' @param watermark_text (`character(1)`) text to display for the watermark -#' @param font_size (`character(1)`) font size for the watermark text +#' @param watermark_text (`character(1)`) text to display for the watermark. +#' @param font_size (`character(1)`) font size for the watermark text. #' #' @return [`teal::teal_transform_module()`] #' -#' @details The module creates a UI with textInput for specifying watermark text and +#' @details The module creates a UI with `textInput` for specifying watermark text and #' font size. -#' the entered watermark text is displayed with a default gridify layout. +#' the entered watermark text is displayed with a default `gridify` layout. #' -#' @import cowplot gridify rtables.officer +#' @import cowplot gridify #' @importFrom grDevices graphics.off #' #' @export @@ -43,7 +43,6 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 res <- within( res, { - watermark_text <- txtWatermark gridify_layout <- gridify::gridifyLayout( nrow = 3L, ncol = 1L, @@ -53,18 +52,17 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 global_gpar = grid::gpar(), background = grid::get.gpar()$fill, adjust_height = FALSE, - object = gridifyObject(row = 2, col = 1), - cells = gridifyCells( - title = gridifyCell(row = 1, col = 1), - footer = gridifyCell(row = 3, col = 1), - watermark = gridifyCell(row = 1:3, col = 1, rot = 45, gpar = grid::gpar(fontsize = numFontsize, alpha = 0.3)) + object = gridify::gridifyObject(row = 2, col = 1), + cells = gridify::gridifyCells( + title = gridify::gridifyCell(row = 1, col = 1), + footer = gridify::gridifyCell(row = 3, col = 1), + watermark = gridify::gridifyCell(row = 1:3, col = 1, rot = 45, gpar = grid::gpar(fontsize = numFontsize, alpha = 0.3)) ) ) }, output_type = output_name, output_name = as.name(output_name), - numFontsize = input$numFontsize, - txtWatermark = input$txtWatermark + numFontsize = input$numFontsize ) res <- within( @@ -73,10 +71,11 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 output_name <- gridify::gridify( object = cowplot::as_grob(output_name), layout = gridify_layout - ) %>% - set_cell("watermark", watermark_text) + ) |> + gridify::set_cell("watermark", watermark_text) }, - output_name = as.name(output_name) + output_name = as.name(output_name), + watermark_text = input$txtWatermark ) }) }) From 7101c03e55b24bd9232b713d6497b97cb9bb66e7 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:22:26 +0000 Subject: [PATCH 08/11] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/watermark_decorator.Rd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/watermark_decorator.Rd b/man/watermark_decorator.Rd index e658257..f6321c9 100644 --- a/man/watermark_decorator.Rd +++ b/man/watermark_decorator.Rd @@ -9,9 +9,9 @@ watermark_decorator(output_name, watermark_text = "", font_size = 90) \arguments{ \item{output_name}{(\code{character(1)}) a name for the output object (e.g., a plot or table).} -\item{watermark_text}{(\code{character(1)}) text to display for the watermark} +\item{watermark_text}{(\code{character(1)}) text to display for the watermark.} -\item{font_size}{(\code{character(1)}) font size for the watermark text} +\item{font_size}{(\code{character(1)}) font size for the watermark text.} } \value{ \code{\link[teal:teal_transform_module]{teal::teal_transform_module()}} @@ -23,7 +23,7 @@ for plots. Note: Currently tables are not supported } \details{ -The module creates a UI with textInput for specifying watermark text and +The module creates a UI with \code{textInput} for specifying watermark text and font size. -the entered watermark text is displayed with a default gridify layout. +the entered watermark text is displayed with a default \code{gridify} layout. } From 66f43388aea83a9762b19d57641027bf8bd203b3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:38:49 +0000 Subject: [PATCH 09/11] [skip roxygen] [skip vbump] Roxygen Man Pages Auto Update --- man/extract_modules_to_yaml.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/extract_modules_to_yaml.Rd b/man/extract_modules_to_yaml.Rd index fb57b37..7b9dd7a 100644 --- a/man/extract_modules_to_yaml.Rd +++ b/man/extract_modules_to_yaml.Rd @@ -4,13 +4,15 @@ \alias{extract_modules_to_yaml} \title{Extract Non-Parent Module Labels to \code{YAML}} \usage{ -extract_modules_to_yaml(mods, filepath) +extract_modules_to_yaml(mods, filepath, verbose = FALSE) } \arguments{ \item{mods}{(\code{teal_module} or \code{teal_modules}) a teal modules object containing the module structure.} \item{filepath}{(\code{character(1)}) character string specifying the output \code{YAML} file path.} + +\item{verbose}{(\code{logical(1)}) whether to print informational messages. Default is \code{FALSE}.} } \value{ Character vector of non-parent module labels From 63cdcd6872f71e200b6202ef9d0fd34c83e67208 Mon Sep 17 00:00:00 2001 From: Konrad Pagacz Date: Tue, 3 Mar 2026 21:11:06 +0100 Subject: [PATCH 10/11] fix all the issues --- NAMESPACE | 87 +++++++++++++++++++---- NEWS.md | 6 +- R/create_rel_risk_transformator.R | 3 +- R/forest_plot_decorator.R | 7 +- R/ggplot_decorator.R | 15 ++-- R/merge_levels_transformator.R | 27 +++++-- R/or_filtering_transformator.R | 11 ++- R/or_filtering_transformator_view_model.R | 2 +- R/patchwork_plot_decorator.R | 4 +- R/r_access_utilities.R | 11 ++- R/title_footer_decorator.R | 7 +- R/watermark_decorator.R | 8 ++- man/TransformationManager.Rd | 74 ------------------- man/extract_modules_to_yaml.Rd | 5 ++ man/merge_level_transformer_ui.Rd | 11 --- 15 files changed, 147 insertions(+), 131 deletions(-) delete mode 100644 man/TransformationManager.Rd delete mode 100644 man/merge_level_transformer_ui.Rd diff --git a/NAMESPACE b/NAMESPACE index 030ec6b..6c91ca8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,31 +12,88 @@ export(patchwork_plot_decorator) export(remove_by_label) export(title_footer_decorator) export(watermark_decorator) -import(R6) -import(checkmate) -import(cowplot) -import(dplyr) -import(ggplot2) -import(ggplotify) -import(gridify) -import(openxlsx) -import(patchwork) -import(rlang) -import(rtables) import(shiny) -import(shinyBS) -import(shinyWidgets) import(teal) -import(tern) -import(yaml) +importFrom(R6,R6Class) +importFrom(checkmate,assert_character) +importFrom(checkmate,assert_class) +importFrom(checkmate,assert_multi_class) +importFrom(checkmate,assert_number) +importFrom(checkmate,assert_true) +importFrom(cowplot,as_grob) importFrom(cowplot,plot_grid) +importFrom(dplyr,filter) +importFrom(ggplot2,.pt) +importFrom(ggplot2,aes) +importFrom(ggplot2,annotate) +importFrom(ggplot2,arrow) +importFrom(ggplot2,coord_cartesian) +importFrom(ggplot2,element_blank) +importFrom(ggplot2,element_line) +importFrom(ggplot2,element_rect) +importFrom(ggplot2,element_text) +importFrom(ggplot2,geom_point) +importFrom(ggplot2,geom_text) +importFrom(ggplot2,ggplot) +importFrom(ggplot2,labs) +importFrom(ggplot2,layer_scales) +importFrom(ggplot2,margin) +importFrom(ggplot2,scale_x_continuous) +importFrom(ggplot2,scale_x_discrete) +importFrom(ggplot2,scale_y_continuous) +importFrom(ggplot2,scale_y_discrete) +importFrom(ggplot2,theme) +importFrom(ggplotify,as.ggplot) importFrom(grDevices,graphics.off) +importFrom(grid,unit) +importFrom(gridify,gridify) +importFrom(gridify,gridifyCell) +importFrom(gridify,gridifyCells) +importFrom(gridify,gridifyLayout) +importFrom(gridify,gridifyObject) +importFrom(gridify,set_cell) importFrom(methods,new) +importFrom(openxlsx,read.xlsx) +importFrom(patchwork,plot_annotation) importFrom(rlang,parse_expr) +importFrom(rtables,as_result_df) +importFrom(shiny,NS) +importFrom(shiny,actionButton) +importFrom(shiny,checkboxInput) +importFrom(shiny,div) +importFrom(shiny,eventReactive) +importFrom(shiny,hr) +importFrom(shiny,insertUI) +importFrom(shiny,modalDialog) +importFrom(shiny,moduleServer) +importFrom(shiny,observe) +importFrom(shiny,observeEvent) +importFrom(shiny,reactive) +importFrom(shiny,reactiveVal) +importFrom(shiny,reactiveValues) +importFrom(shiny,renderText) +importFrom(shiny,renderUI) +importFrom(shiny,req) +importFrom(shiny,selectInput) +importFrom(shiny,showModal) +importFrom(shiny,showNotification) +importFrom(shiny,span) +importFrom(shiny,tagAppendChild) +importFrom(shiny,tagList) +importFrom(shiny,tags) +importFrom(shiny,textInput) +importFrom(shiny,uiOutput) +importFrom(shiny,updateSelectInput) +importFrom(shinyBS,bsModal) +importFrom(shinyWidgets,pickerInput) importFrom(shinyjs,hidden) importFrom(shinyjs,hide) importFrom(shinyjs,show) importFrom(shinyjs,toggle) +importFrom(shinyjs,useShinyjs) +importFrom(teal,teal_transform_module) importFrom(teal.code,eval_code) importFrom(teal.modules.clinical,add_expr) importFrom(teal.modules.clinical,bracket_expr) +importFrom(tern,rtable2gg) +importFrom(yaml,as.yaml) diff --git a/NEWS.md b/NEWS.md index 8768a45..061d58e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,11 +1,7 @@ # Version 0.0.2.9000 -<<<<<<< feature/jgqo373_watermark_decorator -- Refactored the `merge_levels_transformator` to handle the predefined inputs to the transformator([JGQO-323](https://jira.jnj.com/browse/JGQO-323)). -- Added new `watermark_decorator`.([#23](https://github.com/phuse-org/uteals/pull/23)) -======= - Refactored the `merge_levels_transformator` to handle the predefined inputs to the transformator. ->>>>>>> main +- Added new `watermark_decorator`([#23](https://github.com/phuse-org/uteals/pull/23)). # Version 0.0.2 diff --git a/R/create_rel_risk_transformator.R b/R/create_rel_risk_transformator.R index e81dab4..2195382 100644 --- a/R/create_rel_risk_transformator.R +++ b/R/create_rel_risk_transformator.R @@ -12,7 +12,8 @@ #' @param control_group (`character(1)`) one of the existing level from the selected `column_name`. #' @param label_name (`character(1)`) label for the new field or variable. #' -#' @import teal shiny +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList selectInput textInput moduleServer observe updateSelectInput reactive #' #' @return `teal::teal_transform_module` #' diff --git a/R/forest_plot_decorator.R b/R/forest_plot_decorator.R index 2c6cb4b..86356cf 100644 --- a/R/forest_plot_decorator.R +++ b/R/forest_plot_decorator.R @@ -170,7 +170,12 @@ forestplot_x_decorator <- function() { #' printed side-by-side via [cowplot::plot_grid()]. #' #' @return `ggplot` forest plot and table. -#' @import checkmate tern ggplot2 rtables +#' @importFrom checkmate assert_class assert_number assert_character assert_true +#' @importFrom tern rtable2gg +#' @importFrom ggplot2 ggplot theme scale_x_continuous scale_y_continuous coord_cartesian annotate geom_point margin +#' @importFrom ggplot2 element_rect element_blank element_line element_text aes arrow .pt +#' @importFrom rtables as_result_df +#' @importFrom grid unit #' @importFrom cowplot plot_grid #' #' @export diff --git a/R/ggplot_decorator.R b/R/ggplot_decorator.R index e99ac75..0b66d83 100644 --- a/R/ggplot_decorator.R +++ b/R/ggplot_decorator.R @@ -31,7 +31,10 @@ #' of `ggplot` options given in the `plot_options` parameter value. #' The entered `ggplot` options are applied to `ggplot` plot object. #' -#' @import teal shiny ggplot2 +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList tagAppendChild textInput moduleServer reactive req +#' @importFrom ggplot2 labs theme element_text scale_y_continuous scale_x_continuous scale_x_discrete +#' @importFrom ggplot2 scale_y_discrete geom_text layer_scales #' #' @examples #' app <- teal::init( @@ -195,7 +198,7 @@ ggplot_decorator <- function(output_name, output_name <- output_name + ggplot2::scale_y_continuous( breaks = layer_scales(output_name)$y$break_positions(), - labels = trimws(str_split(y_labels_cont, ",")[[1]]) + labels = trimws(strsplit(y_labels_cont, ",")[[1]]) ) }, output_name = as.name(output_name), @@ -212,7 +215,7 @@ ggplot_decorator <- function(output_name, data4, { output_name <- output_name + - ggplot2::scale_x_continuous(breaks = trimws(str_split(x_breaks, ",")[[1]])) + ggplot2::scale_x_continuous(breaks = trimws(strsplit(x_breaks, ",")[[1]])) }, output_name = as.name(output_name), x_breaks = input$x_breaks @@ -229,7 +232,7 @@ ggplot_decorator <- function(output_name, output_name <- output_name + ggplot2::scale_x_continuous( breaks = layer_scales(output_name)$x$break_positions(), - labels = trimws(str_split(x_labels_cont, ",")[[1]]) + labels = trimws(strsplit(x_labels_cont, ",")[[1]]) ) }, output_name = as.name(output_name), @@ -245,7 +248,7 @@ ggplot_decorator <- function(output_name, data7 <- within( data6, { - x_labels_discrete <- trimws(str_split(x_labels_discrete, ",")[[1]]) + x_labels_discrete <- trimws(strsplit(x_labels_discrete, ",")[[1]]) output_name <- output_name + ggplot2::scale_x_discrete(labels = x_labels_discrete) }, output_name = as.name(output_name), @@ -261,7 +264,7 @@ ggplot_decorator <- function(output_name, data8 <- within( data7, { - y_labels_discrete <- trimws(str_split(y_labels_discrete, ",")[[1]]) + y_labels_discrete <- trimws(strsplit(y_labels_discrete, ",")[[1]]) output_name <- output_name + ggplot2::scale_y_discrete(labels = y_labels_discrete) }, output_name = as.name(output_name), diff --git a/R/merge_levels_transformator.R b/R/merge_levels_transformator.R index 670786c..67760c6 100644 --- a/R/merge_levels_transformator.R +++ b/R/merge_levels_transformator.R @@ -1,5 +1,6 @@ -##' R6 Class for managing the transformation objects -TransformationManager <- R6::R6Class( +# TransformationManager R6 Class for managing the transformation objects +# @noRd +TransformationManager <- R6::R6Class( # nolint: object_name_linter. "TransformationManager", public = list( counter = 0, @@ -13,7 +14,7 @@ TransformationManager <- R6::R6Class( add_id = function() { self$counter <- self$counter + 1 self$active_ids(c(self$active_ids(), self$counter)) - return(self$counter) + self$counter }, remove_id = function(id) { self$active_ids(setdiff(self$active_ids(), id)) @@ -27,10 +28,13 @@ TransformationManager <- R6::R6Class( ) #' UI design of the transformator +#' +#' @param id (`character(1)`) the id of the module. +#' @noRd merge_level_transformer_ui <- function(id) { ns <- NS(id) tagList( - useShinyjs(), + shinyjs::useShinyjs(), tags$div(id = ns("transformation_container")), hr(), actionButton(ns("add"), "Add", class = "btn-primary"), @@ -55,7 +59,10 @@ merge_level_transformer_srv <- function(id, data, manager, dataname) { req(input[[paste0("col_name_", idx)]]) col_data <- data()[[dataname]][[input[[paste0("col_name_", idx)]]]] choices <- if (is.factor(col_data)) levels(col_data) else unique(col_data) - selectInput(ns(paste0("levs_", idx)), "Levels to Update", choices = choices, multiple = TRUE, selected = lev_sel) + selectInput( + ns(paste0("levs_", idx)), "Levels to Update", + choices = choices, multiple = TRUE, selected = lev_sel + ) }) } @@ -82,7 +89,10 @@ merge_level_transformer_srv <- function(id, data, manager, dataname) { div( id = body_id, style = "margin-top: 10px;", - selectInput(ns(paste0("col_name_", idx)), "Variable", choices = names(data()[[dataname]]), selected = var_sel), + selectInput( + ns(paste0("col_name_", idx)), "Variable", + choices = names(data()[[dataname]]), selected = var_sel + ), uiOutput(ns(paste0("col_levels_ui_", idx))), textInput(ns(paste0("new_label_", idx)), "New Level Name", value = new_name) ), @@ -189,7 +199,10 @@ merge_level_transformer_srv <- function(id, data, manager, dataname) { #' which columns will be used for possible transformation. #' @param predefined (`list`) the list which has variable name, levels and new label #' -#' @import teal shiny shinyWidgets +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList actionButton hr div tags uiOutput renderUI req +#' @importFrom shiny selectInput textInput moduleServer reactiveVal observeEvent observe eventReactive reactive +#' @importFrom shinyWidgets pickerInput #' @importFrom teal.code eval_code #' @importFrom teal.modules.clinical add_expr bracket_expr #' diff --git a/R/or_filtering_transformator.R b/R/or_filtering_transformator.R index 1b8fa74..d787428 100644 --- a/R/or_filtering_transformator.R +++ b/R/or_filtering_transformator.R @@ -41,10 +41,15 @@ #' #' @param dataname (`character(1)`) Name of the dataset to filter. Pass a single dataset name as a string. #' -#' @import teal shiny shinyWidgets dplyr shinyBS rlang -#' @importFrom methods new -#' @importFrom shinyjs toggle show hidden hide +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList renderText renderUI div span actionButton observeEvent insertUI +#' @importFrom shiny updateSelectInput showNotification showModal modalDialog reactiveValues observe reactive +#' @importFrom shinyWidgets pickerInput +#' @importFrom dplyr filter +#' @importFrom shinyBS bsModal #' @importFrom rlang parse_expr +#' @importFrom methods new +#' @importFrom shinyjs toggle show hidden hide useShinyjs #' #' @return `teal::teal_transform_module` #' diff --git a/R/or_filtering_transformator_view_model.R b/R/or_filtering_transformator_view_model.R index 1c9e305..69a7e43 100644 --- a/R/or_filtering_transformator_view_model.R +++ b/R/or_filtering_transformator_view_model.R @@ -1,6 +1,6 @@ #' View model for [or_filtering_transformator()]. #' -#' @import R6 +#' @importFrom R6 R6Class #' @keywords internal filtering_transformator_model <- R6::R6Class("filtering_transformator_model", public = list( diff --git a/R/patchwork_plot_decorator.R b/R/patchwork_plot_decorator.R index cdf700d..94c66d8 100644 --- a/R/patchwork_plot_decorator.R +++ b/R/patchwork_plot_decorator.R @@ -9,7 +9,9 @@ #' @details The module creates a UI with text controls for plot title and footnote. #' The entered title and footnote text are applied to the patchwork plots. #' -#' @import teal shiny patchwork +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList textInput moduleServer reactive req +#' @importFrom patchwork plot_annotation #' #' @export patchwork_plot_decorator <- function(output_name, label_text = "decorator") { diff --git a/R/r_access_utilities.R b/R/r_access_utilities.R index 408435b..ca71680 100644 --- a/R/r_access_utilities.R +++ b/R/r_access_utilities.R @@ -10,7 +10,7 @@ #' #' @return Character vector of non-parent module labels #' -#' @import yaml +#' @importFrom yaml as.yaml #' @examples #' # Extract modules from mods object to YAML file #' mods <- teal::modules( @@ -19,6 +19,11 @@ #' ) #' labels <- extract_modules_to_yaml(mods, "panel_str_modules.yml") #' +#' # Clean up +#' if (file.exists("panel_str_modules.yml")) { +#' file.remove("panel_str_modules.yml") +#' } +#' #' @export extract_modules_to_yaml <- function(mods, filepath) { # Recursively extract module labels, excluding parent containers @@ -69,7 +74,7 @@ extract_modules_to_yaml <- function(mods, filepath) { #' #' @return Filtered `teal_modules` or `teal_module` object, or `NULL` if none matches. #' -#' @import checkmate +#' @importFrom checkmate assert_multi_class #' @examples #' # Keep only specific modules by label #' mods <- teal::modules( @@ -108,7 +113,7 @@ keep_by_label <- function(x, label) { #' @return The filtered teal modules object with matching modules removed, or `NULL` #' if all modules are removed. #' -#' @import checkmate +#' @importFrom checkmate assert_multi_class #' @examples #' mods <- teal::modules( #' teal::example_module("mod1"), diff --git a/R/title_footer_decorator.R b/R/title_footer_decorator.R index 7e8c086..dda1556 100644 --- a/R/title_footer_decorator.R +++ b/R/title_footer_decorator.R @@ -27,7 +27,12 @@ #' @seealso For the exact Excel workbook layout expected by this function, see the package vignette: #' `vignette("title-footer-decorator-excel-structure", package = "uteals")` #' -#' @import openxlsx ggplotify ggplot2 patchwork teal shiny +#' @importFrom openxlsx read.xlsx +#' @importFrom ggplotify as.ggplot +#' @importFrom ggplot2 labs theme element_text +#' @importFrom patchwork plot_annotation +#' @importFrom teal teal_transform_module +#' @importFrom shiny NS tagList div selectInput checkboxInput uiOutput renderUI textInput moduleServer reactive req #' @importFrom grDevices graphics.off #' #' @examples diff --git a/R/watermark_decorator.R b/R/watermark_decorator.R index b06d00d..ff1f1b2 100644 --- a/R/watermark_decorator.R +++ b/R/watermark_decorator.R @@ -14,7 +14,8 @@ #' font size. #' the entered watermark text is displayed with a default `gridify` layout. #' -#' @import cowplot gridify +#' @importFrom cowplot as_grob +#' @importFrom gridify gridifyLayout gridifyObject gridifyCells gridifyCell gridify set_cell #' @importFrom grDevices graphics.off #' #' @export @@ -56,7 +57,10 @@ watermark_decorator <- function(output_name, watermark_text = "", font_size = 90 cells = gridify::gridifyCells( title = gridify::gridifyCell(row = 1, col = 1), footer = gridify::gridifyCell(row = 3, col = 1), - watermark = gridify::gridifyCell(row = 1:3, col = 1, rot = 45, gpar = grid::gpar(fontsize = numFontsize, alpha = 0.3)) + watermark = gridify::gridifyCell( + row = 1:3, col = 1, rot = 45, + gpar = grid::gpar(fontsize = numFontsize, alpha = 0.3) + ) ) ) }, diff --git a/man/TransformationManager.Rd b/man/TransformationManager.Rd deleted file mode 100644 index 08b8643..0000000 --- a/man/TransformationManager.Rd +++ /dev/null @@ -1,74 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/merge_levels_transformator.R -\name{TransformationManager} -\alias{TransformationManager} -\title{R6 Class for managing the transformation objects} -\description{ -R6 Class for managing the transformation objects - -R6 Class for managing the transformation objects -} -\section{Methods}{ -\subsection{Public methods}{ -\itemize{ -\item \href{#method-TransformationManager-new}{\code{TransformationManager$new()}} -\item \href{#method-TransformationManager-add_id}{\code{TransformationManager$add_id()}} -\item \href{#method-TransformationManager-remove_id}{\code{TransformationManager$remove_id()}} -\item \href{#method-TransformationManager-reset}{\code{TransformationManager$reset()}} -\item \href{#method-TransformationManager-clone}{\code{TransformationManager$clone()}} -} -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-TransformationManager-new}{}}} -\subsection{Method \code{new()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TransformationManager$new(predefined = list())}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-TransformationManager-add_id}{}}} -\subsection{Method \code{add_id()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TransformationManager$add_id()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-TransformationManager-remove_id}{}}} -\subsection{Method \code{remove_id()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TransformationManager$remove_id(id)}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-TransformationManager-reset}{}}} -\subsection{Method \code{reset()}}{ -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TransformationManager$reset()}\if{html}{\out{
}} -} - -} -\if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-TransformationManager-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{TransformationManager$clone(deep = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} -} diff --git a/man/extract_modules_to_yaml.Rd b/man/extract_modules_to_yaml.Rd index 0b43f36..55a3175 100644 --- a/man/extract_modules_to_yaml.Rd +++ b/man/extract_modules_to_yaml.Rd @@ -28,4 +28,9 @@ mods <- teal::modules( ) labels <- extract_modules_to_yaml(mods, "panel_str_modules.yml") +# Clean up +if (file.exists("panel_str_modules.yml")) { + file.remove("panel_str_modules.yml") +} + } diff --git a/man/merge_level_transformer_ui.Rd b/man/merge_level_transformer_ui.Rd deleted file mode 100644 index cb7c87e..0000000 --- a/man/merge_level_transformer_ui.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/merge_levels_transformator.R -\name{merge_level_transformer_ui} -\alias{merge_level_transformer_ui} -\title{UI design of the transformator} -\usage{ -merge_level_transformer_ui(id) -} -\description{ -UI design of the transformator -} From 4f0813e44ff2f204b5ae53c7f9a9f583e6a94a7d Mon Sep 17 00:00:00 2001 From: Konrad Pagacz Date: Tue, 3 Mar 2026 21:12:58 +0100 Subject: [PATCH 11/11] run styler --- R/r_access_utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/r_access_utilities.R b/R/r_access_utilities.R index 7b3ff73..7e3e63f 100644 --- a/R/r_access_utilities.R +++ b/R/r_access_utilities.R @@ -63,7 +63,7 @@ extract_modules_to_yaml <- function(mods, filepath, verbose = FALSE) { if (verbose) { message("Generated ", filepath, " with ", length(non_parent_labels), " non-parent module labels") } - + non_parent_labels }