| Title: | Shared Utilities to Extend the 'teal' Modules |
|---|---|
| Description: | Provides decorators, transformators, and utility functions to extend the 'teal' framework for interactive data analysis applications. Implements methods for data visualization enhancement, statistical data transformations, and workflow integration tools. Designed to support clinical and pharmaceutical research workflows within the 'teal' ecosystem through modular and reusable components. |
| Authors: | Nadia Abraham [aut], Chanchal Bhalla [aut], Peyman Eshghi [aut, cre], Pranith Gourisetty [aut], Sohan Lal [aut], Przemyslaw Posiadala [aut], Alina Tselinina [aut], Konrad Pagacz [aut], PHUSE [cph] |
| Maintainer: | Peyman Eshghi <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4.9000 |
| Built: | 2026-05-28 06:59:36 UTC |
| Source: | https://github.com/phuse-org/uteals |
teal modules.Provides decorator and transformator modules
for teal modules.
Maintainer: Peyman Eshghi [email protected]
Authors:
Peyman Eshghi [email protected]
Nadia Abraham [email protected]
Chanchal Bhalla [email protected]
Pranith Gourisetty [email protected]
Sohan Lal [email protected]
Przemyslaw Posiadala [email protected]
Alina Tselinina [email protected]
Konrad Pagacz [email protected]
Other contributors:
PHUSE [copyright holder]
Useful links:
create_rel_risk_transformator(dataname, column_name, control_group, label_name)create_rel_risk_transformator(dataname, column_name, control_group, label_name)
dataname |
( |
column_name |
( |
control_group |
( |
label_name |
( |
This transformator allows the user to select a column and control group from the dataset and create a relative risk column.
teal::teal_transform_module
app <- teal::init( data = teal.data::teal_data(IRIS = iris, code = "IRIS <- iris"), modules = teal::modules( teal::example_module( transformators = list( create_rel_risk_transformator("IRIS", label_name = "test", control_group = "setosa", column_name = "Species" ) ) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }app <- teal::init( data = teal.data::teal_data(IRIS = iris, code = "IRIS <- iris"), modules = teal::modules( teal::example_module( transformators = list( create_rel_risk_transformator("IRIS", label_name = "test", control_group = "setosa", column_name = "Species" ) ) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }
YAML
Extracts module labels from a teal modules object, filters out parent modules
(grouping containers), and generates a
YAML file with the functional modules.
extract_modules_to_yaml(mods, filepath, verbose = FALSE)extract_modules_to_yaml(mods, filepath, verbose = FALSE)
mods |
( |
filepath |
( |
verbose |
( |
Character vector of non-parent module labels
# Extract modules from mods object to YAML file mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) 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") }# Extract modules from mods object to YAML file mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) 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") }
teal.modules.clinical::tm_g_forest_rsp.
A function to create a UI component for selecting a transform function
for the forest plot x axis.
forestplot_x_decorator()forestplot_x_decorator()
The module creates a UI with a radio control for selecting the transform function. The selected transformation function is applied to the forest plot to update the plot's axis and annotations accordingly.
teal::teal_transform_module Returns a modified plot object with the transformation applied.
library(teal.modules.clinical) data <- teal.data::teal_data() data <- within(data, { ADSL <- teal.modules.clinical::tmc_ex_adsl ADRS <- teal.modules.clinical::tmc_ex_adrs |> dplyr::mutate(AVALC = tern::d_onco_rsp_label(AVALC) |> formatters::with_label("Character Result/Finding")) |> dplyr::filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") }) teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[names(data)] ADSL <- data[["ADSL"]] ADRS <- data[["ADRS"]] arm_ref_comp <- list( ARM = list( ref = "B: Placebo", comp = c("A: Drug X", "C: Combination") ), ARMCD = list( ref = "ARM B", comp = c("ARM A", "ARM C") ) ) app <- teal::init( data = data, modules = teal::modules( teal.modules.clinical::tm_g_forest_rsp( label = "Forest Response", dataname = "ADRS", arm_var = choices_selected( variable_choices(ADSL, c("ARM", "ARMCD")), "ARMCD" ), arm_ref_comp = arm_ref_comp, paramcd = choices_selected( value_choices(ADRS, "PARAMCD", "PARAM"), "INVET" ), subgroup_var = choices_selected( variable_choices(ADSL, names(ADSL)), c("BMRKR2", "SEX") ), strata_var = choices_selected( variable_choices(ADSL, c("STRATA1", "STRATA2")), "STRATA2" ), plot_height = c(600L, 200L, 2000L), decorators = list( plot = forestplot_x_decorator() ), default_responses = list( BESRSPI = list( rsp = c("Stable Disease (SD)", "Not Evaluable (NE)"), levels = c( "Complete Response (CR)", "Partial Response (PR)", "Stable Disease (SD)", "Progressive Disease (PD)", "Not Evaluable (NE)" ) ), INVET = list( rsp = c("Complete Response (CR)", "Partial Response (PR)"), levels = c( "Complete Response (CR)", "Not Evaluable (NE)", "Partial Response (PR)", "Progressive Disease (PD)", "Stable Disease (SD)" ) ), OVRINV = list( rsp = c("Progressive Disease (PD)", "Stable Disease (SD)"), levels = c("Progressive Disease (PD)", "Stable Disease (SD)", "Not Evaluable (NE)") ) ) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }library(teal.modules.clinical) data <- teal.data::teal_data() data <- within(data, { ADSL <- teal.modules.clinical::tmc_ex_adsl ADRS <- teal.modules.clinical::tmc_ex_adrs |> dplyr::mutate(AVALC = tern::d_onco_rsp_label(AVALC) |> formatters::with_label("Character Result/Finding")) |> dplyr::filter(PARAMCD != "OVRINV" | AVISIT == "FOLLOW UP") }) teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[names(data)] ADSL <- data[["ADSL"]] ADRS <- data[["ADRS"]] arm_ref_comp <- list( ARM = list( ref = "B: Placebo", comp = c("A: Drug X", "C: Combination") ), ARMCD = list( ref = "ARM B", comp = c("ARM A", "ARM C") ) ) app <- teal::init( data = data, modules = teal::modules( teal.modules.clinical::tm_g_forest_rsp( label = "Forest Response", dataname = "ADRS", arm_var = choices_selected( variable_choices(ADSL, c("ARM", "ARMCD")), "ARMCD" ), arm_ref_comp = arm_ref_comp, paramcd = choices_selected( value_choices(ADRS, "PARAMCD", "PARAM"), "INVET" ), subgroup_var = choices_selected( variable_choices(ADSL, names(ADSL)), c("BMRKR2", "SEX") ), strata_var = choices_selected( variable_choices(ADSL, c("STRATA1", "STRATA2")), "STRATA2" ), plot_height = c(600L, 200L, 2000L), decorators = list( plot = forestplot_x_decorator() ), default_responses = list( BESRSPI = list( rsp = c("Stable Disease (SD)", "Not Evaluable (NE)"), levels = c( "Complete Response (CR)", "Partial Response (PR)", "Stable Disease (SD)", "Progressive Disease (PD)", "Not Evaluable (NE)" ) ), INVET = list( rsp = c("Complete Response (CR)", "Partial Response (PR)"), levels = c( "Complete Response (CR)", "Not Evaluable (NE)", "Partial Response (PR)", "Progressive Disease (PD)", "Stable Disease (SD)" ) ), OVRINV = list( rsp = c("Progressive Disease (PD)", "Stable Disease (SD)"), levels = c("Progressive Disease (PD)", "Stable Disease (SD)", "Not Evaluable (NE)") ) ) ) ) ) if (interactive()) { shinyApp(app$ui, app$server) }
rtable with x transform settings
Given a
rtables::rtable() object with at least one column with a single value and one column with 2
values, converts table to a ggplot2::ggplot() object and generates an accompanying forest plot. The
table and forest plot are printed side-by-side.
g_forest_with_transform( tbl, col_x = attr(tbl, "col_x"), col_ci = attr(tbl, "col_ci"), vline = 1, forest_header = attr(tbl, "forest_header"), xlim = c(0.1, 10), transform_x = NA, x_at = c(0.1, 1, 10), width_columns = NULL, lbl_col_padding = 0, rel_width_forest = 0.25, font_size = 12, col_symbol_size = attr(tbl, "col_symbol_size"), col = getOption("ggplot2.discrete.colour")[1], ggtheme = NULL, as_list = FALSE )g_forest_with_transform( tbl, col_x = attr(tbl, "col_x"), col_ci = attr(tbl, "col_ci"), vline = 1, forest_header = attr(tbl, "forest_header"), xlim = c(0.1, 10), transform_x = NA, x_at = c(0.1, 1, 10), width_columns = NULL, lbl_col_padding = 0, rel_width_forest = 0.25, font_size = 12, col_symbol_size = attr(tbl, "col_symbol_size"), col = getOption("ggplot2.discrete.colour")[1], ggtheme = NULL, as_list = FALSE )
tbl |
( |
col_x |
( |
col_ci |
( |
vline |
( |
forest_header |
( |
xlim |
( |
transform_x |
( |
x_at |
( |
width_columns |
( |
lbl_col_padding |
( |
rel_width_forest |
( |
font_size |
( |
col_symbol_size |
( |
col |
( |
ggtheme |
( |
as_list |
( |
ggplot forest plot and table.
ggplot decorator
Decorator function to update various settings for
ggplot plot objects
ggplot_decorator( output_name, label_text = "decorator", render_ui = c(), plot_options = list(title = "", footnote = "", y_breaks = "", y_limits_max = "", y_limits_min = "", x_breaks = "", x_labels_discrete = "", x_labels_cont = "", y_labels_discrete = "", y_labels_cont = "", font_size_geom_text = "", font_size_plot_title = "", font_size_axis_title = "", font_size_axis_text = "") )ggplot_decorator( output_name, label_text = "decorator", render_ui = c(), plot_options = list(title = "", footnote = "", y_breaks = "", y_limits_max = "", y_limits_min = "", x_breaks = "", x_labels_discrete = "", x_labels_cont = "", y_labels_discrete = "", y_labels_cont = "", font_size_geom_text = "", font_size_plot_title = "", font_size_axis_title = "", font_size_axis_text = "") )
output_name |
a name for the output plot object. |
label_text |
customized label text for the decorator |
render_ui |
vector of |
plot_options |
named list with the list of values for the |
The module creates a UI with text controls for specifying the list
of ggplot options given in the plot_options parameter value.
The entered ggplot options are applied to ggplot plot object.
teal::teal_transform_module Returns a modified plot object with the transformation applied.
data <- teal.data::teal_data() data <- within(data, { ADSL <- teal.data::rADSL }) teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[names(data)] # teal.modules.general >= 0.6.0 app <- teal::init( data = data, modules = teal::modules( teal.modules.general::tm_g_scatterplot( label = "Scatterplot Choices", x = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), y = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), decorators = list( plot = ggplot_decorator( output_name = "plot", render_ui = c("title", "footnote", "font_size_axis_title") ) ) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }data <- teal.data::teal_data() data <- within(data, { ADSL <- teal.data::rADSL }) teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[names(data)] # teal.modules.general >= 0.6.0 app <- teal::init( data = data, modules = teal::modules( teal.modules.general::tm_g_scatterplot( label = "Scatterplot Choices", x = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), y = teal.transform::data_extract_spec( dataname = "ADSL", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), decorators = list( plot = ggplot_decorator( output_name = "plot", render_ui = c("title", "footnote", "font_size_axis_title") ) ) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }
Recursively filters a teal modules object to keep only modules whose labels
match the specified labels. Removes modules that don't match and empty
parent containers.
keep_by_label(x, label)keep_by_label(x, label)
x |
( |
label |
( |
Filtered teal_modules or teal_module object, or NULL if none matches.
# Keep only specific modules by label mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) filtered_mods <- keep_by_label(mods, c("Data Table", "Disposition"))# Keep only specific modules by label mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) filtered_mods <- keep_by_label(mods, c("Data Table", "Disposition"))
merge_levels_transformator(dataname, predefined = list())merge_levels_transformator(dataname, predefined = list())
dataname |
( |
predefined |
( |
This transformator allows the user to select a column from the dataset and merge levels of this column into a new level. Only selected levels are affected.
teal::teal_transform_module
app <- teal::init( data = teal.data::teal_data(IRIS = iris, code = "IRIS <- iris"), modules = teal::modules( teal::example_module( transformators = list(merge_levels_transformator( dataname = "IRIS", predefined = list( list("Species", "setosa", "SETOSA_WITHIN_FIX"), list("Petal.Width", c(0.2, 0.3, 0.5), 12) ) )) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }app <- teal::init( data = teal.data::teal_data(IRIS = iris, code = "IRIS <- iris"), modules = teal::modules( teal::example_module( transformators = list(merge_levels_transformator( dataname = "IRIS", predefined = list( list("Species", "setosa", "SETOSA_WITHIN_FIX"), list("Petal.Width", c(0.2, 0.3, 0.5), 12) ) )) ) ) ) if (interactive()) { shiny::shinyApp(app$ui, app$server) }
This transformator provides users with flexible, dynamic filtering capabilities for datasets.
Each instance of the transformator operates on a single dataset. Users can define multiple filter blocks, where:
Conditions within each block are combined with logical AND.
Multiple blocks are combined with logical OR.
This allows creating complex filter expressions like:
(Condition1 AND Condition2) OR (Condition3 AND Condition4)
To apply filtering across multiple datasets, users can instantiate multiple instances of this module, each configured for a different dataset. Each module call is independent and manages filters for its specific dataset.
Supported Data Types & Expressions:
Supports filtering on character, factor, and numeric columns.
Conditions can use operators: ==, !=, <,
>, <=, >=, %in%, !%in%.
Conditions are specified as simple expressions, e.g.,
columnA == 'value'
columnB != 5
columnC >= 10
Each block's conditions are combined with AND.
Multiple blocks are combined with OR.
Features:
Add Multiple OR Blocks: Dynamically add new blocks for alternative conditions.
Add Conditions: Within each block, add multiple conditions, with duplicate prevention.
Preview Filter Expression: Generate and display the current combined filter expression.
Remove Conditions: Remove individual conditions within a block.
Expression Generation: The resulting expression can be directly used
with dplyr::filter() or similar functions.
Usage Pattern:
Call the module multiple times with different dataset names to filter multiple datasets independently.
Each call manages its own filter state and expression.
Users can build complex filters per dataset and apply or combine them as needed.
or_filtering_transformator(dataname)or_filtering_transformator(dataname)
dataname |
( |
teal::teal_transform_module
app <- teal::init( data = teal.data::teal_data(IRIS = iris), modules = teal::modules(teal::example_module( transformators = list(or_filtering_transformator("IRIS")) )) ) if (interactive()) { shinyApp(app$ui, app$server) }app <- teal::init( data = teal.data::teal_data(IRIS = iris), modules = teal::modules(teal::example_module( transformators = list(or_filtering_transformator("IRIS")) )) ) if (interactive()) { shinyApp(app$ui, app$server) }
Decorator function to add plot title and footnote to patchwork plots
patchwork_plot_decorator(output_name, label_text = "decorator")patchwork_plot_decorator(output_name, label_text = "decorator")
output_name |
( |
label_text |
( |
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.
(teal.data::qenv) Returns a modified plot object with the transformation applied.
Recursively removes modules from a teal modules structure that match the specified labels.
remove_by_label(x, label)remove_by_label(x, label)
x |
( |
label |
( |
The filtered teal modules object with matching modules removed, or NULL
if all modules are removed.
mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) # Remove a single module filtered_mods <- remove_by_label(mods, "Deaths") # Remove multiple modules filtered_mods <- remove_by_label(mods, c("Deaths", "Lab Summary Table"))mods <- teal::modules( teal::example_module("mod1"), teal::example_module("mod2") ) # Remove a single module filtered_mods <- remove_by_label(mods, "Deaths") # Remove multiple modules filtered_mods <- remove_by_label(mods, c("Deaths", "Lab Summary Table"))
Report Manager Module
tm_report_manager(reports_path = "reports", auto_save = TRUE)tm_report_manager(reports_path = "reports", auto_save = TRUE)
reports_path |
character. Absolute path where reports should be stored. |
auto_save |
logical. Whether to save active report whenever there are any changes made. |
This module supports collaborative work on teal reports, generated by teal.reporter
package. This module extends functionalities of teal.reporter and allows to store
reports in chosen path. Reports will be stored as JSON files inside folders named after
reports.
app <- teal::init( data = teal.data::teal_data(IRIS = iris), modules = teal::modules( teal::example_module(transformators = list(or_filtering_transformator("IRIS"))), tm_report_manager() ) ) if (interactive()) { shinyApp(app$ui, app$server) }app <- teal::init( data = teal.data::teal_data(IRIS = iris), modules = teal::modules( teal::example_module(transformators = list(or_filtering_transformator("IRIS"))), tm_report_manager() ) ) if (interactive()) { shinyApp(app$ui, app$server) }
A function to create a UI component for selecting watermark text
for plots.
Note: Currently tables are not supported
watermark_decorator(output_name, watermark_text = "", font_size = 90)watermark_decorator(output_name, watermark_text = "", font_size = 90)
output_name |
( |
watermark_text |
( |
font_size |
( |
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.