Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.Rcheck
*.tar.gz
*.Rproj
.Rproj.user
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Imports:
teal.code,
tern,
yaml,
gridify,
teal.modules.clinical
Suggests:
forcats,
Expand Down
86 changes: 73 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,89 @@ export(or_filtering_transformator)
export(patchwork_plot_decorator)
export(remove_by_label)
export(title_footer_decorator)
import(R6)
import(checkmate)
import(dplyr)
import(ggplot2)
import(ggplotify)
import(openxlsx)
import(patchwork)
import(rlang)
import(rtables)
export(watermark_decorator)
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)
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 0.0.2.9000

- Refactored the `merge_levels_transformator` to handle the predefined inputs to the transformator.
- Added new `watermark_decorator`([#23](https://github.com/phuse-org/uteals/pull/23)).

# Version 0.0.2

Expand Down
3 changes: 2 additions & 1 deletion R/create_rel_risk_transformator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`
#'
Expand Down
7 changes: 6 additions & 1 deletion R/forest_plot_decorator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions R/ggplot_decorator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down
27 changes: 20 additions & 7 deletions R/merge_levels_transformator.R
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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))
Expand All @@ -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"),
Expand All @@ -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
)
})
}

Expand All @@ -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)
),
Expand Down Expand Up @@ -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
#'
Expand Down
11 changes: 8 additions & 3 deletions R/or_filtering_transformator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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`
#'
Expand Down
2 changes: 1 addition & 1 deletion R/or_filtering_transformator_view_model.R
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 3 additions & 1 deletion R/patchwork_plot_decorator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
13 changes: 9 additions & 4 deletions R/r_access_utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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(
Expand All @@ -21,6 +21,11 @@
#' labels <- extract_modules_to_yaml(mods, "panel_str_modules.yml")
#' unlink("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, verbose = FALSE) {
# Recursively extract module labels, excluding parent containers
Expand Down Expand Up @@ -58,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
}

Expand All @@ -74,7 +79,7 @@ extract_modules_to_yaml <- function(mods, filepath, verbose = FALSE) {
#'
#' @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(
Expand Down Expand Up @@ -113,7 +118,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"),
Expand Down
7 changes: 6 additions & 1 deletion R/title_footer_decorator.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading