Type: Package
Title: General Modules for 'teal' Applications
Version: 0.4.1
Date: 2025-04-01
Description: Prebuilt 'shiny' modules containing tools for viewing data, visualizing data, understanding missing and outlier values within your data and performing simple data analysis. This extends 'teal' framework that supports reproducible research and analysis.
License: Apache License 2.0
URL: https://insightsengineering.github.io/teal.modules.general/, https://github.com/insightsengineering/teal.modules.general/
BugReports: https://github.com/insightsengineering/teal.modules.general/issues
Depends: ggmosaic (≥ 0.3.0), ggplot2 (≥ 3.4.0), R (≥ 4.1), shiny (≥ 1.6.0), teal (≥ 0.16.0), teal.transform (≥ 0.6.0)
Imports: checkmate (≥ 2.1.0), colourpicker (≥ 1.3.0), dplyr (≥ 1.0.5), DT (≥ 0.13), forcats (≥ 1.0.0), generics (≥ 0.1.3), ggExtra (≥ 0.10.1), ggpmisc (≥ 0.4.3), ggpp (≥ 0.5.8-1), ggrepel (≥ 0.9.6), goftest (≥ 1.2-3), grid, gridExtra (≥ 2.3), htmlwidgets (≥ 1.6.4), jsonlite (≥ 1.8.9), lattice (≥ 0.18-4), lifecycle (≥ 0.2.0), MASS (≥ 7.3-60), rtables (≥ 0.6.11), scales (≥ 1.3.0), shinyjs (≥ 2.1.0), shinyTree (≥ 0.2.8), shinyvalidate (≥ 0.1.3), shinyWidgets (≥ 0.5.1), sparkline (≥ 2.0), stats, stringr (≥ 1.4.1), teal.code (≥ 0.6.1), teal.data (≥ 0.7.0), teal.logger (≥ 0.3.2), teal.reporter (≥ 0.4.0), teal.widgets (≥ 0.4.3), tern (≥ 0.9.7), tibble (≥ 2.0.0), tidyr (≥ 0.8.3), tools, utils
Suggests: knitr (≥ 1.42), logger (≥ 0.2.0), nestcolor (≥ 0.1.0), pkgload, rlang (≥ 1.0.0), rmarkdown (≥ 2.23), roxy.shinylive, rvest, shinytest2, testthat (≥ 3.1.9), withr (≥ 2.0.0)
VignetteBuilder: knitr, rmarkdown
Config/Needs/verdepcheck: haleyjeppson/ggmosaic, tidyverse/ggplot2, rstudio/shiny, insightsengineering/teal, insightsengineering/teal.slice, insightsengineering/teal.transform, mllg/checkmate, tidyverse/dplyr, rstudio/DT, tidyverse/forcats, r-lib/lifecycle, r-lib/scales, daattali/shinyjs, shinyTree/shinyTree, rstudio/shinyvalidate, dreamRs/shinyWidgets, tidyverse/stringr, insightsengineering/teal.code, insightsengineering/teal.data, insightsengineering/teal.logger, insightsengineering/teal.reporter, insightsengineering/teal.widgets, insightsengineering/tern, tidyverse/tibble, tidyverse/tidyr, daattali/colourpicker, daattali/ggExtra, aphalo/ggpmisc, aphalo/ggpp, slowkow/ggrepel, baddstats/goftest, ramnathv/htmlwidgets, jeroen/jsonlite, yihui/knitr, daroczig/logger, deepayan/lattice, insightsengineering/nestcolor, r-lib/pkgload, r-lib/rlang, rstudio/rmarkdown, insightsengineering/roxy.shinylive, insightsengineering/rtables, tidyverse/rvest, htmlwidgets/sparkline, rstudio/shinytest2, r-lib/testthat, r-lib/withr
Config/Needs/website: insightsengineering/nesttemplate
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-04-01 18:33:59 UTC; unardid
Author: Dawid Kaledkowski [aut, cre], Pawel Rucki [aut], Mahmoud Hallal [aut], Ondrej Slama [ctb], Maciej Nasinski [aut], Konrad Pagacz [aut], Nikolas Burkoff [aut], F. Hoffmann-La Roche AG [cph, fnd]
Maintainer: Dawid Kaledkowski <dawid.kaledkowski@roche.com>
Repository: CRAN
Date/Publication: 2025-04-01 21:20:01 UTC

teal.modules.general: General modules to add to a teal application

Description

The modules in this package are generic modules that should work with any data set (not necessarily for clinical trials data).

Author(s)

Maintainer: Dawid Kaledkowski dawid.kaledkowski@roche.com

Authors:

Other contributors:

See Also

Useful links:


Add labels for facets to a ggplot2 object

Description

Enhances a ggplot2 plot by adding labels that describe the faceting variables along the x and y axes.

Usage

add_facet_labels(p, xfacet_label = NULL, yfacet_label = NULL)

Arguments

p

(ggplot2) object to which facet labels will be added.

xfacet_label

(character) Label for the facet along the x-axis. If NULL, no label is added. If a vector, labels are joined with " & ".

yfacet_label

(character) Label for the facet along the y-axis. Similar behavior to xfacet_label.

Value

Returns grid or grob object (to be drawn with grid.draw)

Examples

library(ggplot2)
library(grid)

p <- ggplot(mtcars) +
  aes(x = mpg, y = disp) +
  geom_point() +
  facet_grid(gear ~ cyl)

xfacet_label <- "cylinders"
yfacet_label <- "gear"
res <- add_facet_labels(p, xfacet_label, yfacet_label)
grid.newpage()
grid.draw(res)

grid.newpage()
grid.draw(add_facet_labels(p, xfacet_label = NULL, yfacet_label))
grid.newpage()
grid.draw(add_facet_labels(p, xfacet_label, yfacet_label = NULL))
grid.newpage()
grid.draw(add_facet_labels(p, xfacet_label = NULL, yfacet_label = NULL))


Call a function with a character vector for the ... argument

Description

Call a function with a character vector for the ... argument

Usage

call_fun_dots(fun, str_args)

Arguments

fun

(character) Name of a function where the ... argument shall be replaced by values from str_args.

str_args

(character) A character vector that the function shall be executed with

Value

Value of call to fun with arguments specified in str_args.


S3 generic for sparkline widget HTML

Description

Generates the sparkline HTML code corresponding to the input array. For numeric variables creates a box plot, for character and factors - bar plot. Produces an empty string for variables of other types.

Usage

create_sparklines(arr, width = 150, ...)

## S3 method for class 'logical'
create_sparklines(arr, ...)

## S3 method for class 'numeric'
create_sparklines(arr, width = 150, ...)

## S3 method for class 'character'
create_sparklines(arr, ...)

## S3 method for class 'factor'
create_sparklines(arr, width = 150, bar_spacing = 5, bar_width = 20, ...)

## S3 method for class 'Date'
create_sparklines(arr, width = 150, bar_spacing = 5, bar_width = 20, ...)

## S3 method for class 'POSIXct'
create_sparklines(arr, width = 150, bar_spacing = 5, bar_width = 20, ...)

## S3 method for class 'POSIXlt'
create_sparklines(arr, width = 150, bar_spacing = 5, bar_width = 20, ...)

## Default S3 method:
create_sparklines(arr, width = 150, ...)

Arguments

arr

vector of any type and length

width

numeric the width of the sparkline widget (pixels)

...

list additional options passed to bar plots of jquery.sparkline; see ⁠jquery.sparkline docs⁠

bar_spacing

numeric the spacing between the bars (in pixels)

bar_width

numeric the width of the bars (in pixels)

Value

Character string containing HTML code of the sparkline HTML widget.


Creates observers updating the currently selected column

Description

The created observers update the column currently selected in the left-hand side tabset panel.

Usage

establish_updating_selection(datanames, input, plot_var, columns_names)

Arguments

datanames

(character) the name of the dataset

input

(session$input) the shiny session input

plot_var

(list) the list containing the currently selected dataset (tab) and its column names

columns_names

(environment) the environment containing bindings for each dataset

Note

Creates an observer for each dataset (each tab in the tabset panel).


Get stats for x-y pairs in scatterplot matrix

Description

Uses stats::cor.test() per default for all numerical input variables and converts results to character vector. Could be extended if different stats for different variable types are needed. Meant to be called from lattice::panel.text().

Usage

get_scatterplotmatrix_stats(
  x,
  y,
  .f = stats::cor.test,
  .f_args = list(),
  round_stat = 2,
  round_pval = 4
)

Arguments

x, y

(numeric) vectors of data values. x and y must have the same length.

.f

(function) function that accepts x and y as formula input ~ x + y. Default stats::cor.test.

.f_args

(list) of arguments to be passed to .f.

round_stat

(integer(1)) optional, number of decimal places to use when rounding the estimate.

round_pval

(integer(1)) optional, number of decimal places to use when rounding the p-value.

Details

Presently we need to use a formula input for stats::cor.test because na.fail only gets evaluated when a formula is passed (see below).

x = c(1,3,5,7,NA)
y = c(3,6,7,8,1)
stats::cor.test(x, y, na.action = "na.fail")
stats::cor.test(~ x + y,  na.action = "na.fail")

Value

Character with stats. For stats::cor.test() correlation coefficient and p-value.

Examples

set.seed(1)
x <- runif(25, 0, 1)
y <- runif(25, 0, 1)
x[c(3, 10, 18)] <- NA

get_scatterplotmatrix_stats(x, y, .f = stats::cor.test, .f_args = list(method = "pearson"))
get_scatterplotmatrix_stats(x, y, .f = stats::cor.test, .f_args = list(
  method = "pearson",
  na.action = na.fail
))


Include CSS files from ⁠/inst/css/⁠ package directory to application header

Description

system.file should not be used to access files in other packages, it does not work with devtools. Therefore, we redefine this method in each package as needed. Thus, we do not export this method

Usage

include_css_files(pattern = "*")

Arguments

pattern

(character) optional, regular expression to match the file names to be included.

Value

HTML code that includes CSS files.


JavaScript condition to check if a specific tab is active

Description

JavaScript condition to check if a specific tab is active

Usage

is_tab_active_js(id, name)

Arguments

id

(character(1)) the id of the tab panel with tabs.

name

(character(1)) the name of the tab.

Value

JavaScript expression to be used in shiny::conditionalPanel() to determine if the specified tab is active.


Plot variable

Description

Creates summary plot with statistics relevant to data type.

Usage

plot_var_summary(
  var,
  var_lab,
  wrap_character = NULL,
  numeric_as_factor,
  display_density = is.numeric(var),
  remove_NA_hist = FALSE,
  outlier_definition,
  records_for_factor,
  ggplot2_args
)

Arguments

var

vector of any type to be plotted. For numeric variables it produces histogram with density line, for factors it creates frequency plot

var_lab

text describing selected variable to be displayed on the plot

wrap_character

(numeric) number of characters at which to wrap text values of var

numeric_as_factor

(logical) should the numeric variable be treated as a factor

display_density

(logical) should density estimation be displayed for numeric values

remove_NA_hist

(logical) should NA values be removed for histogram of factor like variables

outlier_definition

if 0 no outliers are removed, otherwise outliers (those more than outlier_definition*IQR below/above Q1/Q3 be removed)

records_for_factor

(numeric) if the number of factor levels is >= than this value then a graph of the factors isn't shown, only a list of values

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

Value

plot


Removes the outlier observation from an array

Description

Removes the outlier observation from an array

Usage

remove_outliers_from(var, outlier_definition)

Arguments

var

(numeric) a numeric vector

outlier_definition

(numeric) if 0 then no outliers are removed, otherwise outliers (those more than ⁠outlier_definition*IQR below/above Q1/Q3⁠) are removed

Value

(numeric) vector without the outlier values


Renders a single tab in the left-hand side tabset panel

Description

Renders a single tab in the left-hand side tabset panel. The rendered tab contains information about one dataset out of many presented in the module.

Usage

render_single_tab(
  dataset_name,
  parent_dataname,
  output,
  data,
  input,
  columns_names,
  plot_var
)

Arguments

dataset_name

(character) the name of the dataset contained in the rendered tab

parent_dataname

(character) the name of a parent dataname to filter out variables from

output

(session$output) the shiny session output

data

(teal_data) the object containing all datasets

input

(session$input) the shiny session input

columns_names

(environment) the environment containing bindings for each dataset

plot_var

(list) the list containing the currently selected dataset (tab) and its column names


Renders the text headlining a single tab in the left-hand side tabset panel

Description

Renders the text headlining a single tab in the left-hand side tabset panel

Usage

render_tab_header(dataset_name, output, data)

Arguments

dataset_name

(character) the name of the dataset of the tab

output

(session$output) the shiny session output

data

(teal_data) the object containing all datasets


Renders the table for a single dataset in the left-hand side tabset panel

Description

The table contains column names, column labels, small summary about NA values and sparkline (if appropriate).

Usage

render_tab_table(
  dataset_name,
  parent_dataname,
  output,
  data,
  input,
  columns_names,
  plot_var
)

Arguments

dataset_name

(character) the name of the dataset

parent_dataname

(character) the name of a parent dataname to filter out variables from

output

(session$output) the shiny session output

data

(teal_data) the object containing all datasets

input

(session$input) the shiny session input

columns_names

(environment) the environment containing bindings for each dataset

plot_var

(list) the list containing the currently selected dataset (tab) and its column names


Renders the left-hand side tabset panel of the module

Description

Renders the left-hand side tabset panel of the module

Usage

render_tabset_panel_content(
  datanames,
  parent_dataname,
  output,
  data,
  input,
  columns_names,
  plot_var
)

Arguments

datanames

(character) the name of the dataset

parent_dataname

(character) the name of a parent dataname to filter out variables from

output

(session$output) the shiny session output

data

(teal_data) the object containing all datasets

input

(session$input) the shiny session input

columns_names

(environment) the environment containing bindings for each dataset

plot_var

(list) the list containing the currently selected dataset (tab) and its column names


Subset decorators based on the scope

Description

Subset decorators based on the scope

Usage

select_decorators(decorators, scope)

Arguments

decorators

(named list) of list decorators to subset.

scope

(character) a character vector of decorator names to include.

Value

Subsetted list with all decorators to include. It can be an empty list if none of the scope exists in decorators argument.


Shared parameters documentation

Description

Defines common arguments shared across multiple functions in the package to avoid repetition by using inheritParams.

Arguments

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

rotate_xaxis_labels

(logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

basic_table_args

(basic_table_args) object created by teal.widgets::basic_table_args() with settings for the module table. The argument is merged with options variable teal.basic_table_args and default module setup.

For more details see the vignette: vignette("custom-basic-table-arguments", package = "teal.widgets")

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

alpha

(integer(1) or integer(3)) optional, specifies point opacity.

  • When the length of alpha is one: the plot points will have a fixed opacity.

  • When the length of alpha is three: the plot points opacity are dynamically adjusted based on vector of value, min, and max.

size

(integer(1) or integer(3)) optional, specifies point size.

  • When the length of size is one: the plot point sizes will have a fixed size.

  • When the length of size is three: the plot points size are dynamically adjusted based on vector of value, min, and max.

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.


Wrappers around srv_transform_teal_data that allows to decorate the data

Description

Wrappers around srv_transform_teal_data that allows to decorate the data

Usage

srv_decorate_teal_data(id, data, decorators, expr, expr_is_reactive = FALSE)

ui_decorate_teal_data(id, decorators, ...)

Arguments

id

(character(1)) shiny module instance id.

data

(reactive returning teal_data)

expr

(expression or reactive) to evaluate on the output of the decoration. When an expression it must be inline code. See within() Default is NULL which won't evaluate any appending code.

expr_is_reactive

(logical(1)) whether expr is a reactive expression that skips defusing the argument.

Details

srv_decorate_teal_data is a wrapper around srv_transform_teal_data that allows to decorate the data with additional expressions. When original teal_data object is in error state, it will show that error first.

ui_decorate_teal_data is a wrapper around ui_transform_teal_data.


teal module: Principal component analysis

Description

Module conducts principal component analysis (PCA) on a given dataset and offers different ways of visualizing the outcomes, including elbow plot, circle plot, biplot, and eigenvector plot. Additionally, it enables dynamic customization of plot aesthetics, such as opacity, size, and font size, through UI inputs.

Usage

tm_a_pca(
  label = "Principal Component Analysis",
  dat,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  rotate_xaxis_labels = FALSE,
  font_size = c(12, 8, 20),
  alpha = c(1, 0, 1),
  size = c(2, 1, 8),
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

dat

(data_extract_spec or list of multiple data_extract_spec) specifying columns used to compute PCA.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

rotate_xaxis_labels

(logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).

font_size

(numeric) optional, specifies font size. It controls the font size for plot titles, axis labels, and legends.

  • If vector of length == 1 then the font sizes will have a fixed size.

  • while vector of value, min, and max allows dynamic adjustment.

alpha

(integer(1) or integer(3)) optional, specifies point opacity.

  • When the length of alpha is one: the plot points will have a fixed opacity.

  • When the length of alpha is three: the plot points opacity are dynamically adjusted based on vector of value, min, and max.

size

(integer(1) or integer(3)) optional, specifies point size.

  • When the length of size is one: the plot point sizes will have a fixed size.

  • When the length of size is three: the plot points size are dynamically adjusted based on vector of value, min, and max.

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_a_pca(
   ..., # arguments for module
   decorators = list(
     elbow_plot = teal_transform_module(...), # applied to the `elbow_plot` output
     circle_plot = teal_transform_module(...), # applied to the `circle_plot` output
     biplot = teal_transform_module(...), # applied to the `biplot` output
     eigenvector_plot = teal_transform_module(...) # applied to the `eigenvector_plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples


# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  USArrests <- USArrests
})

app <- init(
  data = data,
  modules = modules(
    tm_a_pca(
      "PCA",
      dat = data_extract_spec(
        dataname = "USArrests",
        select = select_spec(
          choices = variable_choices(
            data = data[["USArrests"]], c("Murder", "Assault", "UrbanPop", "Rape")
          ),
          selected = c("Murder", "Assault"),
          multiple = TRUE
        ),
        filter = NULL
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_a_pca(
      "PCA",
      dat = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          choices = variable_choices(
            data = data[["ADSL"]], c("BMRKR1", "AGE", "EOSDY")
          ),
          selected = c("BMRKR1", "AGE"),
          multiple = TRUE
        ),
        filter = NULL
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Scatterplot and regression analysis

Description

Module for visualizing regression analysis, including scatterplots and various regression diagnostics plots. It allows users to explore the relationship between a set of regressors and a response variable, visualize residuals, and identify outliers.

Usage

tm_a_regression(
  label = "Regression Analysis",
  regressor,
  response,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  alpha = c(1, 0, 1),
  size = c(2, 1, 8),
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  pre_output = NULL,
  post_output = NULL,
  default_plot_type = 1,
  default_outlier_label = "USUBJID",
  label_segment_threshold = c(0.5, 0, 10),
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

regressor

(data_extract_spec or list of multiple data_extract_spec) Regressor variables from an incoming dataset with filtering and selecting.

response

(data_extract_spec or list of multiple data_extract_spec) Response variables from an incoming dataset with filtering and selecting.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

alpha

(integer(1) or integer(3)) optional, specifies point opacity.

  • When the length of alpha is one: the plot points will have a fixed opacity.

  • When the length of alpha is three: the plot points opacity are dynamically adjusted based on vector of value, min, and max.

size

(integer(1) or integer(3)) optional, specifies point size.

  • When the length of size is one: the plot point sizes will have a fixed size.

  • When the length of size is three: the plot points size are dynamically adjusted based on vector of value, min, and max.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Response vs Regressor", "Residuals vs Fitted", "Scale-Location", "Cook's distance", "Residuals vs Leverage", "Cook's dist vs Leverage").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

default_plot_type

(numeric) optional, defaults to "Response vs Regressor".

  1. Response vs Regressor

  2. Residuals vs Fitted

  3. Normal Q-Q

  4. Scale-Location

  5. Cook's distance

  6. Residuals vs Leverage

  7. Cook's dist vs Leverage

default_outlier_label

(character) optional, default column selected to label outliers.

label_segment_threshold

(numeric(1) or numeric(3)) Minimum distance between label and point on the plot that triggers the creation of a line segment between the two. This may happen when the label cannot be placed next to the point as it overlaps another label or point. The value is used as the min.segment.length parameter to the ggrepel::geom_text_repel() function.

It can take the following forms:

  • numeric(1): Fixed value used for the minimum distance and the slider is not presented in the UI.

  • numeric(3): A slider is presented in the UI (under "Plot settings") to adjust the minimum distance dynamically.

    It takes the form of c(value, min, max) and it is passed to the value_min_max argument in teal.widgets::optionalSliderInputValMinMax.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_a_regression(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using regression plots" via vignette("using-regression-plots", package = "teal.modules.general").

Examples


# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- CO2
})

app <- init(
  data = data,
  modules = modules(
    tm_a_regression(
      label = "Regression",
      response = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = "uptake",
          selected = "uptake",
          multiple = FALSE,
          fixed = TRUE
        )
      ),
      regressor = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["CO2"]], c("conc", "Treatment")),
          selected = "conc",
          multiple = TRUE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_a_regression(
      label = "Regression",
      response = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = "BMRKR1",
          selected = "BMRKR1",
          multiple = FALSE,
          fixed = TRUE
        )
      ),
      regressor = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")),
          selected = "AGE",
          multiple = TRUE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Data table viewer

Description

Module provides a dynamic and interactive way to view data.frames in a teal application. It uses the DT package to display data tables in a paginated, searchable, and sortable format, which helps to enhance data exploration and analysis.

Usage

tm_data_table(
  label = "Data Table",
  variables_selected = list(),
  datasets_selected = deprecated(),
  datanames = if (missing(datasets_selected)) "all" else datasets_selected,
  dt_args = list(),
  dt_options = list(searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100),
    scrollX = TRUE),
  server_rendering = FALSE,
  pre_output = NULL,
  post_output = NULL,
  transformators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

variables_selected

(⁠named list⁠) Character vectors of the variables (i.e. columns) which should be initially shown for each dataset. Names of list elements should correspond to the names of the datasets available in the app. If no entry is specified for a dataset, the first six variables from that dataset will initially be shown.

datasets_selected

(character) [Deprecated] A vector of datasets which should be shown and in what order. Use datanames instead.

datanames

(character) Names of the datasets relevant to the item. There are 2 reserved values that have specific behaviors:

  • The keyword "all" includes all datasets available in the data passed to the teal application.

  • NULL hides the sidebar panel completely.

  • If transformators are specified, their datanames are automatically added to this datanames argument.

dt_args

(⁠named list⁠) Additional arguments to be passed to DT::datatable() (must not include data or options).

dt_options

(⁠named list⁠) The options argument to DT::datatable. By default list(searching = FALSE, pageLength = 30, lengthMenu = c(5, 15, 30, 100), scrollX = TRUE)

server_rendering

(logical) should the data table be rendered server side (see server argument of DT::renderDataTable())

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

Details

The DT package has an option DT.TOJSON_ARGS to show Inf and NA in data tables. Configure the DT.TOJSON_ARGS option via options(DT.TOJSON_ARGS = list(na = "string")) before running the module. Note though that sorting of numeric columns with NA/Inf will be lexicographic not numerical.

Value

Object of class teal_module to be used in teal applications.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  iris <- iris
})

app <- init(
  data = data,
  modules = modules(
    tm_data_table(
      variables_selected = list(
        iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
      ),
      dt_args = list(caption = "IRIS Table Caption")
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_data_table(
      variables_selected = list(ADSL = c("STUDYID", "USUBJID", "SUBJID", "SITEID", "AGE", "SEX")),
      dt_args = list(caption = "ADSL Table Caption")
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: File viewer

Description

The file viewer module provides a tool to view static files. Supported formats include text formats, PDF, PNG APNG, JPEG SVG, WEBP, GIF and BMP.

Usage

tm_file_viewer(
  label = "File Viewer Module",
  input_path = list(`Current Working Directory` = ".")
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

input_path

(list) of the input paths, optional. Each element can be:

Paths can be specified as absolute paths or relative to the running directory of the application. Default to the current working directory if not supplied.

Value

Object of class teal_module to be used in teal applications.

Examples in Shinylive

example-1

Open in Shinylive

Examples

data <- teal_data()
data <- within(data, {
  data <- data.frame(1)
})

app <- init(
  data = data,
  modules = modules(
    tm_file_viewer(
      input_path = list(
        folder = system.file("sample_files", package = "teal.modules.general"),
        png = system.file("sample_files/sample_file.png", package = "teal.modules.general"),
        txt = system.file("sample_files/sample_file.txt", package = "teal.modules.general"),
        url = "https://fda.gov/files/drugs/published/Portable-Document-Format-Specifications.pdf"
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Front page

Description

Creates a simple front page for teal applications, displaying introductory text, tables, additional html or shiny tags, and footnotes.

Usage

tm_front_page(
  label = "Front page",
  header_text = character(0),
  tables = list(),
  additional_tags = tagList(),
  footnotes = character(0),
  show_metadata = deprecated(),
  datanames = if (missing(show_metadata)) NULL else "all",
  transformators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

header_text

(character vector) text to be shown at the top of the module, for each element, if named the name is shown first in bold as a header followed by the value. The first element's header is displayed larger than the others.

tables

(⁠named list⁠ of data.frames) tables to be shown in the module.

additional_tags

(shiny.tag.list or html) additional shiny tags or html to be included after the table, for example to include an image, tagList(tags$img(src = "image.png")) or to include further html, HTML("html text here").

footnotes

(character vector) of text to be shown at the bottom of the module, for each element, if named the name is shown first in bold, followed by the value.

show_metadata

(logical) [Deprecated] indicating whether the metadata of the datasets be available on the module. Metadata shown automatically when datanames set.

datanames

(character) Names of the datasets relevant to the item. There are 2 reserved values that have specific behaviors:

  • The keyword "all" includes all datasets available in the data passed to the teal application.

  • NULL hides the sidebar panel completely.

  • If transformators are specified, their datanames are automatically added to this datanames argument.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

Value

Object of class teal_module to be used in teal applications.

Examples in Shinylive

example-1

Open in Shinylive

Examples

data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
  attr(ADSL, "metadata") <- list("Author" = "NEST team", "data_source" = "synthetic data")
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

table_1 <- data.frame(Info = c("A", "B"), Text = c("A", "B"))
table_2 <- data.frame(`Column 1` = c("C", "D"), `Column 2` = c(5.5, 6.6), `Column 3` = c("A", "B"))
table_3 <- data.frame(Info = c("E", "F"), Text = c("G", "H"))

table_input <- list(
  "Table 1" = table_1,
  "Table 2" = table_2,
  "Table 3" = table_3
)

app <- init(
  data = data,
  modules = modules(
    tm_front_page(
      header_text = c(
        "Important information" = "It can go here.",
        "Other information" = "Can go here."
      ),
      tables = table_input,
      additional_tags = HTML("Additional HTML or shiny tags go here <br>"),
      footnotes = c("X" = "is the first footnote", "Y is the second footnote")
    )
  )
) |>
  modify_header(tags$h1("Sample Application")) |>
  modify_footer(tags$p("Application footer"))

if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Stack plots of variables and show association with reference variable

Description

Module provides functionality for visualizing the distribution of variables and their association with a reference variable. It supports configuring the appearance of the plots, including themes and whether to show associations.

Usage

tm_g_association(
  label = "Association",
  ref,
  vars,
  show_association = TRUE,
  plot_height = c(600, 400, 5000),
  plot_width = NULL,
  distribution_theme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic",
    "void"),
  association_theme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic",
    "void"),
  pre_output = NULL,
  post_output = NULL,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

ref

(data_extract_spec or list of multiple data_extract_spec) Reference variable, must accepts a data_extract_spec with select_spec(multiple = FALSE) to ensure single selection option.

vars

(data_extract_spec or list of multiple data_extract_spec) Variables to be associated with the reference variable.

show_association

(logical) optional, whether show association of vars with reference variable. Defaults to TRUE.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

distribution_theme, association_theme

(character) optional, ggplot2 themes to be used by default. Default to "gray".

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Bivariate1", "Bivariate2").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_association(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using association plot" via vignette("using-association-plot", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- CO2
  factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
  CO2[factors] <- lapply(CO2[factors], as.character)
})

app <- init(
  data = data,
  modules = modules(
    tm_g_association(
      ref = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = "Plant",
          fixed = FALSE
        )
      ),
      vars = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = "Treatment",
          multiple = TRUE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_association(
      ref = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(
            data[["ADSL"]],
            c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2")
          ),
          selected = "RACE",
          fixed = FALSE
        )
      ),
      vars = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variables:",
          choices = variable_choices(
            data[["ADSL"]],
            c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2")
          ),
          selected = "BMRKR2",
          multiple = TRUE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Univariate and bivariate visualizations

Description

Module enables the creation of univariate and bivariate plots, facilitating the exploration of data distributions and relationships between two variables.

Usage

tm_g_bivariate(
  label = "Bivariate Plots",
  x,
  y,
  row_facet = NULL,
  col_facet = NULL,
  facet = !is.null(row_facet) || !is.null(col_facet),
  color = NULL,
  fill = NULL,
  size = NULL,
  use_density = FALSE,
  color_settings = FALSE,
  free_x_scales = FALSE,
  free_y_scales = FALSE,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  rotate_xaxis_labels = FALSE,
  swap_axes = FALSE,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

x

(data_extract_spec or list of multiple data_extract_spec) Variable names selected to plot along the x-axis by default. Can be numeric, factor or character. No empty selections are allowed.

y

(data_extract_spec or list of multiple data_extract_spec) Variable names selected to plot along the y-axis by default. Can be numeric, factor or character.

row_facet

(data_extract_spec or list of multiple data_extract_spec) optional, specification of the data variable(s) to use for faceting rows.

col_facet

(data_extract_spec or list of multiple data_extract_spec) optional, specification of the data variable(s) to use for faceting columns.

facet

(logical) optional, specifies whether the facet encodings ui elements are toggled on and shown to the user by default. Defaults to TRUE if either row_facet or column_facet are supplied.

color

(data_extract_spec or list of multiple data_extract_spec) optional, specification of the data variable(s) selected for the outline color inside the coloring settings. It will be applied when color_settings is set to TRUE.

fill

(data_extract_spec or list of multiple data_extract_spec) optional, specification of the data variable(s) selected for the fill color inside the coloring settings. It will be applied when color_settings is set to TRUE.

size

(data_extract_spec or list of multiple data_extract_spec) optional, specification of the data variable(s) selected for the size of geom_point plots inside the coloring settings. It will be applied when color_settings is set to TRUE.

use_density

(logical) optional, indicates whether to plot density (TRUE) or frequency (FALSE). Defaults to frequency (FALSE).

color_settings

(logical) Whether coloring, filling and size should be applied and UI tool offered to the user.

free_x_scales

(logical) optional, whether X scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).

free_y_scales

(logical) optional, whether Y scaling shall be changeable. Does not allow scaling to be changed by default (FALSE).

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

rotate_xaxis_labels

(logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).

swap_axes

(logical) optional, whether to swap X and Y axes. Defaults to FALSE.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Details

This is a general module to visualize 1 & 2 dimensional data.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_bivariate(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using bivariate plot" via vignette("using-bivariate-plot", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- data.frame(CO2)
})

app <- init(
  data = data,
  modules = tm_g_bivariate(
    x = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "conc",
        fixed = FALSE
      )
    ),
    y = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "uptake",
        multiple = FALSE,
        fixed = FALSE
      )
    ),
    row_facet = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "Type",
        fixed = FALSE
      )
    ),
    col_facet = data_extract_spec(
      dataname = "CO2",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["CO2"]]),
        selected = "Treatment",
        fixed = FALSE
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = tm_g_bivariate(
    x = data_extract_spec(
      dataname = "ADSL",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["ADSL"]]),
        selected = "AGE",
        fixed = FALSE
      )
    ),
    y = data_extract_spec(
      dataname = "ADSL",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["ADSL"]]),
        selected = "SEX",
        multiple = FALSE,
        fixed = FALSE
      )
    ),
    row_facet = data_extract_spec(
      dataname = "ADSL",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["ADSL"]]),
        selected = "ARM",
        fixed = FALSE
      )
    ),
    col_facet = data_extract_spec(
      dataname = "ADSL",
      select = select_spec(
        label = "Select variable:",
        choices = variable_choices(data[["ADSL"]]),
        selected = "COUNTRY",
        fixed = FALSE
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Distribution analysis

Description

Module is designed to explore the distribution of a single variable within a given dataset. It offers several tools, such as histograms, Q-Q plots, and various statistical tests to visually and statistically analyze the variable's distribution.

Usage

tm_g_distribution(
  label = "Distribution Module",
  dist_var,
  strata_var = NULL,
  group_var = NULL,
  freq = FALSE,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  bins = c(30L, 1L, 100L),
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

dist_var

(data_extract_spec or list of multiple data_extract_spec) Variable(s) for which the distribution will be analyzed.

strata_var

(data_extract_spec or list of multiple data_extract_spec) Categorical variable used to split the distribution analysis.

group_var

(data_extract_spec or list of multiple data_extract_spec) Variable used for faceting plot into multiple panels.

freq

(logical) optional, whether to display frequency (TRUE) or density (FALSE). Defaults to density (FALSE).

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Histogram", "QQplot").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

bins

(integer(1) or integer(3)) optional, specifies the number of bins for the histogram.

  • When the length of bins is one: The histogram bins will have a fixed size based on the bins provided.

  • When the length of bins is three: The histogram bins are dynamically adjusted based on vector of value, min, and max. Defaults to c(30L, 1L, 100L).

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

pre_output

(shiny.tag) optional,
with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, with text placed after the output to put the output into context. For example the shiny::helpText() elements are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators::

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_distribution(
   ..., # arguments for module
   decorators = list(
     histogram_plot = teal_transform_module(...), # applied only to `histogram_plot` output
     qq_plot = teal_transform_module(...), # applied only to `qq_plot` output
     summary_table = teal_transform_module(...), # applied only to `summary_table` output
     test_table = teal_transform_module(...) # applied only to `test_table` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples

# general data example
data <- teal_data()
data <- within(data, {
  iris <- iris
})

app <- init(
  data = data,
  modules = list(
    tm_g_distribution(
      dist_var = data_extract_spec(
        dataname = "iris",
        select = select_spec(variable_choices("iris"), "Petal.Length")
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

vars1 <- choices_selected(
  variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")),
  selected = NULL
)

app <- init(
  data = data,
  modules = modules(
    tm_g_distribution(
      dist_var = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
          selected = "BMRKR1",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      strata_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars1,
          multiple = TRUE
        )
      ),
      group_var = data_extract_spec(
        dataname = "ADSL",
        filter = filter_spec(
          vars = vars1,
          multiple = TRUE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Response plot

Description

Generates a response plot for a given response and x variables. This module allows users customize and add annotations to the plot depending on the module's arguments. It supports showing the counts grouped by other variable facets (by row / column), swapping the coordinates, show count annotations and displaying the response plot as frequency or density.

Usage

tm_g_response(
  label = "Response Plot",
  response,
  x,
  row_facet = NULL,
  col_facet = NULL,
  coord_flip = FALSE,
  count_labels = TRUE,
  rotate_xaxis_labels = FALSE,
  freq = FALSE,
  plot_height = c(600, 400, 5000),
  plot_width = NULL,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

response

(data_extract_spec or list of multiple data_extract_spec) Which variable to use as the response. You can define one fixed column by setting fixed = TRUE inside the select_spec.

The data_extract_spec must not allow multiple selection in this case.

x

(data_extract_spec or list of multiple data_extract_spec) Specifies which variable to use on the X-axis of the response plot. Allow the user to select multiple columns from the data allowed in teal.

The data_extract_spec must not allow multiple selection in this case.

row_facet

(data_extract_spec or list of multiple data_extract_spec) optional specification of the data variable(s) to use for faceting rows.

col_facet

(data_extract_spec or list of multiple data_extract_spec) optional specification of the data variable(s) to use for faceting columns.

coord_flip

(logical(1)) Indicates whether to flip coordinates between x and response. The default value is FALSE and it will show the x variable on the x-axis and the response variable on the y-axis.

count_labels

(logical(1)) Indicates whether to show count labels. Defaults to TRUE.

rotate_xaxis_labels

(logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).

freq

(logical(1)) Indicates whether to display frequency (TRUE) or density (FALSE). Defaults to density (FALSE).

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_response(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using response plot" via vignette("using-response-plot", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  mtcars <- mtcars
  for (v in c("cyl", "vs", "am", "gear")) {
    mtcars[[v]] <- as.factor(mtcars[[v]])
  }
})

app <- init(
  data = data,
  modules = modules(
    tm_g_response(
      label = "Response Plots",
      response = data_extract_spec(
        dataname = "mtcars",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["mtcars"]], c("cyl", "gear")),
          selected = "cyl",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      x = data_extract_spec(
        dataname = "mtcars",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["mtcars"]], c("vs", "am")),
          selected = "vs",
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_response(
      label = "Response Plots",
      response = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")),
          selected = "BMRKR2",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")),
          selected = "RACE",
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Scatterplot

Description

Generates a customizable scatterplot using ggplot2. This module allows users to select variables for the x and y axes, color and size encodings, faceting options, and more. It supports log transformations, trend line additions, and dynamic adjustments of point opacity and size through UI controls.

Usage

tm_g_scatterplot(
  label = "Scatterplot",
  x,
  y,
  color_by = NULL,
  size_by = NULL,
  row_facet = NULL,
  col_facet = NULL,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  alpha = c(1, 0, 1),
  shape = shape_names,
  size = c(5, 1, 15),
  max_deg = 5L,
  rotate_xaxis_labels = FALSE,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  pre_output = NULL,
  post_output = NULL,
  table_dec = 4,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

x

(data_extract_spec or list of multiple data_extract_spec) Specifies variable names selected to plot along the x-axis by default.

y

(data_extract_spec or list of multiple data_extract_spec) Specifies variable names selected to plot along the y-axis by default.

color_by

(data_extract_spec or list of multiple data_extract_spec) optional, defines the color encoding. If NULL then no color encoding option will be displayed.

size_by

(data_extract_spec or list of multiple data_extract_spec) optional, defines the point size encoding. If NULL then no size encoding option will be displayed.

row_facet

(data_extract_spec or list of multiple data_extract_spec) optional, specifies the variable(s) for faceting rows.

col_facet

(data_extract_spec or list of multiple data_extract_spec) optional, specifies the variable(s) for faceting columns.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

alpha

(integer(1) or integer(3)) optional, specifies point opacity.

  • When the length of alpha is one: the plot points will have a fixed opacity.

  • When the length of alpha is three: the plot points opacity are dynamically adjusted based on vector of value, min, and max.

shape

(character) optional, character vector with the names of the shape, e.g. c("triangle", "square", "circle"). It defaults to shape_names. This is a complete list from vignette("ggplot2-specs", package="ggplot2").

size

(integer(1) or integer(3)) optional, specifies point size.

  • When the length of size is one: the plot point sizes will have a fixed size.

  • When the length of size is three: the plot points size are dynamically adjusted based on vector of value, min, and max.

max_deg

(integer) optional, maximum degree for the polynomial trend line. Must not be less than 1.

rotate_xaxis_labels

(logical) optional, whether to rotate plot X axis labels. Does not rotate by default (FALSE).

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

table_dec

(integer) optional, number of decimal places used to round numeric values in the table.

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_scatterplot(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using scatterplot" via vignette("using-scatterplot", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  CO2 <- CO2
})

app <- init(
  data = data,
  modules = modules(
    tm_g_scatterplot(
      label = "Scatterplot Choices",
      x = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
          selected = "conc",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      y = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
          selected = "uptake",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      color_by = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(
            data[["CO2"]],
            c("Plant", "Type", "Treatment", "conc", "uptake")
          ),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      size_by = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
          selected = "uptake",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      row_facet = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      col_facet = data_extract_spec(
        dataname = "CO2",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_scatterplot(
      label = "Scatterplot Choices",
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")),
          selected = "AGE",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      y = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")),
          selected = "BMRKR1",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      color_by = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(
            data[["ADSL"]],
            c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1")
          ),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      size_by = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
          selected = "AGE",
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      row_facet = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      ),
      col_facet = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")),
          selected = NULL,
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Scatterplot matrix

Description

Generates a scatterplot matrix from selected variables from datasets. Each plot within the matrix represents the relationship between two variables, providing the overview of correlations and distributions across selected data.

Usage

tm_g_scatterplotmatrix(
  label = "Scatterplot Matrix",
  variables,
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

variables

(data_extract_spec or list of multiple data_extract_spec) Specifies plotting variables from an incoming dataset with filtering and selecting. In case of data_extract_spec use select_spec(..., ordered = TRUE) if plot elements should be rendered according to selection order.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_g_scatterplotmatrix(
   ..., # arguments for module
   decorators = list(
     plot = teal_transform_module(...) # applied to the `plot` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using scatterplot matrix" via vignette("using-scatterplot-matrix", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  countries <- data.frame(
    id = c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"),
    government = factor(
      c(2, 2, 2, 1, 2, 2, 1, 1, 1, 2),
      labels = c("Monarchy", "Republic")
    ),
    language_family = factor(
      c(1, 3, 3, 3, 3, 2, 1, 1, 3, 1),
      labels = c("Germanic", "Hellenic", "Romance")
    ),
    population = c(83, 67, 60, 47, 10, 11, 17, 11, 0.6, 9),
    area = c(357, 551, 301, 505, 92, 132, 41, 30, 2.6, 83),
    gdp = c(3.4, 2.7, 2.1, 1.4, 0.3, 0.2, 0.7, 0.5, 0.1, 0.4),
    debt = c(2.1, 2.3, 2.4, 2.6, 2.3, 2.4, 2.3, 2.4, 2.3, 2.4)
  )
  sales <- data.frame(
    id = 1:50,
    country_id = sample(
      c("DE", "FR", "IT", "ES", "PT", "GR", "NL", "BE", "LU", "AT"),
      size = 50,
      replace = TRUE
    ),
    year = sort(sample(2010:2020, 50, replace = TRUE)),
    venue = sample(c("small", "medium", "large", "online"), 50, replace = TRUE),
    cancelled = sample(c(TRUE, FALSE), 50, replace = TRUE),
    quantity = rnorm(50, 100, 20),
    costs = rnorm(50, 80, 20),
    profit = rnorm(50, 20, 10)
  )
})
join_keys(data) <- join_keys(
  join_key("countries", "countries", "id"),
  join_key("sales", "sales", "id"),
  join_key("countries", "sales", c("id" = "country_id"))
)

app <- init(
  data = data,
  modules = modules(
    tm_g_scatterplotmatrix(
      label = "Scatterplot matrix",
      variables = list(
        data_extract_spec(
          dataname = "countries",
          select = select_spec(
            label = "Select variables:",
            choices = variable_choices(data[["countries"]]),
            selected = c("area", "gdp", "debt"),
            multiple = TRUE,
            ordered = TRUE,
            fixed = FALSE
          )
        ),
        data_extract_spec(
          dataname = "sales",
          filter = filter_spec(
            label = "Select variable:",
            vars = "country_id",
            choices = value_choices(data[["sales"]], "country_id"),
            selected = c("DE", "FR", "IT", "PT", "GR", "NL", "BE", "LU", "AT"),
            multiple = TRUE
          ),
          select = select_spec(
            label = "Select variables:",
            choices = variable_choices(data[["sales"]], c("quantity", "costs", "profit")),
            selected = c("quantity", "costs", "profit"),
            multiple = TRUE,
            ordered = TRUE,
            fixed = FALSE
          )
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
  ADRS <- teal.data::rADRS
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_g_scatterplotmatrix(
      label = "Scatterplot matrix",
      variables = list(
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            label = "Select variables:",
            choices = variable_choices(data[["ADSL"]]),
            selected = c("AGE", "RACE", "SEX"),
            multiple = TRUE,
            ordered = TRUE,
            fixed = FALSE
          )
        ),
        data_extract_spec(
          dataname = "ADRS",
          filter = filter_spec(
            label = "Select endpoints:",
            vars = c("PARAMCD", "AVISIT"),
            choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")),
            selected = "INVET - END OF INDUCTION",
            multiple = TRUE
          ),
          select = select_spec(
            label = "Select variables:",
            choices = variable_choices(data[["ADRS"]]),
            selected = c("AGE", "AVAL", "ADY"),
            multiple = TRUE,
            ordered = TRUE,
            fixed = FALSE
          )
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Missing data analysis

Description

This module analyzes missing data in data.frames to help users explore missing observations and gain insights into the completeness of their data. It is useful for clinical data analysis within the context of CDISC standards and adaptable for general data analysis purposes.

Usage

tm_missing_data(
  label = "Missing data",
  plot_height = c(600, 400, 5000),
  plot_width = NULL,
  datanames = "all",
  parent_dataname = "ADSL",
  ggtheme = c("classic", "gray", "bw", "linedraw", "light", "dark", "minimal", "void"),
  ggplot2_args = list(`Combinations Hist` = teal.widgets::ggplot2_args(labs =
    list(caption = NULL)), `Combinations Main` = teal.widgets::ggplot2_args(labs =
    list(title = NULL))),
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

datanames

(character) Names of the datasets relevant to the item. There are 2 reserved values that have specific behaviors:

  • The keyword "all" includes all datasets available in the data passed to the teal application.

  • NULL hides the sidebar panel completely.

  • If transformators are specified, their datanames are automatically added to this datanames argument.

parent_dataname

(character(1)) Specifies the parent dataset name. Default is ADSL for CDISC data. If provided and exists, enables additional analysis "by subject". For non-CDISC data, this parameter can be ignored.

ggtheme

(character) optional, specifies the default ggplot2 theme for plots. Defaults to classic.

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Summary Obs", "Summary Patients", "Combinations Main", "Combinations Hist", "By Subject").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_missing_data(
   ..., # arguments for module
   decorators = list(
     summary_plot = teal_transform_module(...), # applied only to `summary_plot` output
     combination_plot = teal_transform_module(...), # applied only to `combination_plot` output
     by_subject_plot = teal_transform_module(...), # applied only to `by_subject_plot` output
     table = teal_transform_module(...) # applied only to `table` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples

# general example data
data <- teal_data()
data <- within(data, {
  require(nestcolor)

  add_nas <- function(x) {
    x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
    x
  }

  iris <- iris
  mtcars <- mtcars

  iris[] <- lapply(iris, add_nas)
  mtcars[] <- lapply(mtcars, add_nas)
  mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
  mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
})

app <- init(
  data = data,
  modules = modules(
    tm_missing_data(parent_dataname = "mtcars")
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC example data
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  ADSL <- teal.data::rADSL
  ADRS <- rADRS
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_missing_data()
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Outliers analysis

Description

Module to analyze and identify outliers using different methods such as IQR, Z-score, and Percentiles, and offers visualizations including box plots, density plots, and cumulative distribution plots to help interpret the outliers.

Usage

tm_outliers(
  label = "Outliers Module",
  outlier_var,
  categorical_var = NULL,
  ggtheme = c("gray", "bw", "linedraw", "light", "dark", "minimal", "classic", "void"),
  ggplot2_args = teal.widgets::ggplot2_args(),
  plot_height = c(600, 200, 2000),
  plot_width = NULL,
  pre_output = NULL,
  post_output = NULL,
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

outlier_var

(data_extract_spec or list of multiple data_extract_spec) Specifies variable(s) to be analyzed for outliers.

categorical_var

(data_extract_spec or list of multiple data_extract_spec) optional, specifies the categorical variable(s) to split the selected outlier variables on.

ggtheme

(character) optional, ggplot2 theme to be used by default. Defaults to "gray".

ggplot2_args

(ggplot2_args) optional, object created by teal.widgets::ggplot2_args() with settings for all the plots or named list of ggplot2_args objects for plot-specific settings. The argument is merged with options variable teal.ggplot2_args and default module setup.

List names should match the following: c("default", "Boxplot", "Density Plot", "Cumulative Distribution Plot").

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets").

plot_height

(numeric) optional, specifies the plot height as a three-element vector of value, min, and max intended for use with a slider UI element.

plot_width

(numeric) optional, specifies the plot width as a three-element vector of value, min, and max for a slider encoding the plot width.

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_outliers(
   ..., # arguments for module
   decorators = list(
     box_plot = teal_transform_module(...), # applied only to `box_plot` output
     density_plot = teal_transform_module(...), # applied only to `density_plot` output
     cumulative_plot = teal_transform_module(...), # applied only to `cumulative_plot` output
     table = teal_transform_module(...) # applied only to `table` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples


# general data example
data <- teal_data()
data <- within(data, {
  CO2 <- CO2
  CO2[["primary_key"]] <- seq_len(nrow(CO2))
})
join_keys(data) <- join_keys(join_key("CO2", "CO2", "primary_key"))

vars <- choices_selected(variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")))

app <- init(
  data = data,
  modules = modules(
    tm_outliers(
      outlier_var = list(
        data_extract_spec(
          dataname = "CO2",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["CO2"]], c("conc", "uptake")),
            selected = "uptake",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        data_extract_spec(
          dataname = "CO2",
          filter = filter_spec(
            vars = vars,
            choices = value_choices(data[["CO2"]], vars$selected),
            selected = value_choices(data[["CO2"]], vars$selected),
            multiple = TRUE
          )
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor)))
vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl))



app <- init(
  data = data,
  modules = modules(
    tm_outliers(
      outlier_var = list(
        data_extract_spec(
          dataname = "ADSL",
          select = select_spec(
            label = "Select variable:",
            choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")),
            selected = "AGE",
            multiple = FALSE,
            fixed = FALSE
          )
        )
      ),
      categorical_var = list(
        data_extract_spec(
          dataname = "ADSL",
          filter = filter_spec(
            vars = vars,
            choices = value_choices(data[["ADSL"]], vars$selected),
            selected = value_choices(data[["ADSL"]], vars$selected),
            multiple = TRUE
          )
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Cross-table

Description

Generates a simple cross-table of two variables from a dataset with custom options for showing percentages and sub-totals.

Usage

tm_t_crosstable(
  label = "Cross Table",
  x,
  y,
  show_percentage = TRUE,
  show_total = TRUE,
  pre_output = NULL,
  post_output = NULL,
  basic_table_args = teal.widgets::basic_table_args(),
  transformators = list(),
  decorators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

x

(data_extract_spec or list of multiple data_extract_spec) Object with all available choices with pre-selected option for variable X - row values. In case of data_extract_spec use select_spec(..., ordered = TRUE) if table elements should be rendered according to selection order.

y

(data_extract_spec or list of multiple data_extract_spec) Object with all available choices with pre-selected option for variable Y - column values.

data_extract_spec must not allow multiple selection in this case.

show_percentage

(logical(1)) Indicates whether to show percentages (relevant only when x is a factor). Defaults to TRUE.

show_total

(logical(1)) Indicates whether to show total column. Defaults to TRUE.

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

basic_table_args

(basic_table_args) object created by teal.widgets::basic_table_args() with settings for the module table. The argument is merged with options variable teal.basic_table_args and default module setup.

For more details see the vignette: vignette("custom-basic-table-arguments", package = "teal.widgets")

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

decorators

[Experimental] (named list of lists of teal_transform_module) optional, decorator for tables or plots included in the module output reported. The decorators are applied to the respective output objects.

See section "Decorating Module" below for more details.

Value

Object of class teal_module to be used in teal applications.

Decorating Module

This module generates the following objects, which can be modified in place using decorators:

A Decorator is applied to the specific output using a named list of teal_transform_module objects. The name of this list corresponds to the name of the output to which the decorator is applied. See code snippet below:

tm_t_crosstable(
   ..., # arguments for module
   decorators = list(
     table = teal_transform_module(...) # applied to the `table` output
   )
)

For additional details and examples of decorators, refer to the vignette vignette("decorate-module-output", package = "teal.modules.general").

To learn more please refer to the vignette vignette("transform-module-output", package = "teal") or the teal::teal_transform_module() documentation.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Note

For more examples, please see the vignette "Using cross table" via vignette("using-cross-table", package = "teal.modules.general").

Examples

# general data example
data <- teal_data()
data <- within(data, {
  mtcars <- mtcars
  for (v in c("cyl", "vs", "am", "gear")) {
    mtcars[[v]] <- as.factor(mtcars[[v]])
  }
  mtcars[["primary_key"]] <- seq_len(nrow(mtcars))
})
join_keys(data) <- join_keys(join_key("mtcars", "mtcars", "primary_key"))

app <- init(
  data = data,
  modules = modules(
    tm_t_crosstable(
      label = "Cross Table",
      x = data_extract_spec(
        dataname = "mtcars",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["mtcars"]], c("cyl", "vs", "am", "gear")),
          selected = c("cyl", "gear"),
          multiple = TRUE,
          ordered = TRUE,
          fixed = FALSE
        )
      ),
      y = data_extract_spec(
        dataname = "mtcars",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["mtcars"]], c("cyl", "vs", "am", "gear")),
          selected = "vs",
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC data example
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_t_crosstable(
      label = "Cross Table",
      x = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], subset = function(data) {
            idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt"))
            return(names(data)[idx])
          }),
          selected = "COUNTRY",
          multiple = TRUE,
          ordered = TRUE,
          fixed = FALSE
        )
      ),
      y = data_extract_spec(
        dataname = "ADSL",
        select = select_spec(
          label = "Select variable:",
          choices = variable_choices(data[["ADSL"]], subset = function(data) {
            idx <- vapply(data, is.factor, logical(1))
            return(names(data)[idx])
          }),
          selected = "SEX",
          multiple = FALSE,
          fixed = FALSE
        )
      )
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


teal module: Variable browser

Description

Module provides provides a detailed summary and visualization of variable distributions for data.frame objects, with interactive features to customize analysis.

Usage

tm_variable_browser(
  label = "Variable Browser",
  datasets_selected = deprecated(),
  datanames = if (missing(datasets_selected)) "all" else datasets_selected,
  parent_dataname = "ADSL",
  pre_output = NULL,
  post_output = NULL,
  ggplot2_args = teal.widgets::ggplot2_args(),
  transformators = list()
)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

datasets_selected

(character) [Deprecated] vector of datasets to show, please use the datanames argument.

datanames

(character) Names of the datasets relevant to the item. There are 2 reserved values that have specific behaviors:

  • The keyword "all" includes all datasets available in the data passed to the teal application.

  • NULL hides the sidebar panel completely.

  • If transformators are specified, their datanames are automatically added to this datanames argument.

parent_dataname

(character(1)) string specifying a parent dataset. If it exists in datanames then an extra checkbox will be shown to allow users to not show variables in other datasets which exist in this dataname. This is typically used to remove ADSL columns in CDISC data. In non CDISC data this can be ignored. Defaults to "ADSL".

pre_output

(shiny.tag) optional, text or UI element to be displayed before the module's output, providing context or a title. with text placed before the output to put the output into context. For example a title.

post_output

(shiny.tag) optional, text or UI element to be displayed after the module's output, adding context or further instructions. Elements like shiny::helpText() are useful.

ggplot2_args

(ggplot2_args) object created by teal.widgets::ggplot2_args() with settings for the module plot. The argument is merged with options variable teal.ggplot2_args and default module setup.

For more details see the vignette: vignette("custom-ggplot2-arguments", package = "teal.widgets")

transformators

(list of teal_transform_module) that will be applied to transform module's data input. To learn more check vignette("transform-input-data", package = "teal").

Details

Numeric columns with fewer than 30 distinct values can be treated as either discrete or continuous with a checkbox allowing users to switch how they are treated(if < 6 unique values then the default is discrete, otherwise it is continuous).

Value

Object of class teal_module to be used in teal applications.

Examples in Shinylive

example-1

Open in Shinylive

example-2

Open in Shinylive

Examples

# general data example
data <- teal_data()
data <- within(data, {
  iris <- iris
  mtcars <- mtcars
  women <- women
  faithful <- faithful
  CO2 <- CO2
})

app <- init(
  data = data,
  modules = modules(
    tm_variable_browser(
      label = "Variable browser"
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

# CDISC example data
library(sparkline)
data <- teal_data()
data <- within(data, {
  ADSL <- teal.data::rADSL
  ADTTE <- teal.data::rADTTE
})
join_keys(data) <- default_cdisc_join_keys[names(data)]

app <- init(
  data = data,
  modules = modules(
    tm_variable_browser(
      label = "Variable browser"
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}


Validates the variable browser inputs

Description

Validates the variable browser inputs

Usage

validate_input(input, plot_var, data)

Arguments

input

(session$input) the shiny session input

plot_var

(list) list of a data frame and an array of variable names

data

(teal_data) the datasets passed to the module

Value

logical TRUE if validations pass; a shiny validation error otherwise


Summarize NAs.

Description

Summarizes occurrence of missing values in vector.

Usage

var_missings_info(x)

Arguments

x

vector of any type and length

Value

Character string describing NA occurrence.


Summarizes variable

Description

Creates html summary with statistics relevant to data type. For numeric values it returns central tendency measures, for factor returns level counts, for Date date range, for other just number of levels.

Usage

var_summary_table(x, numeric_as_factor, dt_rows, outlier_definition)

Arguments

x

vector of any type

numeric_as_factor

logical should the numeric variable be treated as a factor

dt_rows

numeric current/latest DT page length

outlier_definition

If 0 no outliers are removed, otherwise outliers (those more than ⁠outlier_definition*IQR below/above Q1/Q3⁠ be removed)

Value

text with simple statistics.


Get icons to represent variable types in dataset

Description

Get icons to represent variable types in dataset

Usage

variable_type_icons(var_type)

Arguments

var_type

(character) of R internal types (classes).

Value

(character) vector of HTML icons corresponding to data type in each column.


Generate a string for a variable including its label

Description

Generate a string for a variable including its label

Usage

varname_w_label(
  var_names,
  dataset,
  wrap_width = 80,
  prefix = NULL,
  suffix = NULL
)

Arguments

var_names

(character) Name of variable to extract labels from.

dataset

(dataset) Name of analysis dataset.

wrap_width

(numeric) Number of characters to wrap original label to. Defaults to 80.

prefix, suffix

(character) String to paste to the beginning/end of the variable name with label.

Value

(character) String with variable name and label.