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:
Pawel Rucki pawel.rucki@roche.com
Mahmoud Hallal mahmoud.hallal@roche.com
Maciej Nasinski
Konrad Pagacz
Nikolas Burkoff
Other contributors:
Ondrej Slama ondrej.slama@roche.com [contributor]
F. Hoffmann-La Roche AG [copyright holder, funder]
See Also
Useful links:
-
https://github.com/insightsengineering/teal.modules.general/
Report bugs at https://github.com/insightsengineering/teal.modules.general/issues
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 |
( |
xfacet_label |
( |
yfacet_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 |
( |
str_args |
( |
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 |
|
... |
|
bar_spacing |
|
bar_width |
|
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 |
( |
input |
( |
plot_var |
( |
columns_names |
( |
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 |
( |
.f |
( |
.f_args |
( |
round_stat |
( |
round_pval |
( |
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 |
( |
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 |
( |
name |
( |
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_as_factor |
( |
display_density |
( |
remove_NA_hist |
( |
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 |
( |
ggplot2_args |
( For more details see the vignette: |
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 |
( |
outlier_definition |
( |
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 |
( |
parent_dataname |
( |
output |
( |
data |
( |
input |
( |
columns_names |
( |
plot_var |
( |
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 |
( |
output |
( |
data |
( |
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 |
( |
parent_dataname |
( |
output |
( |
data |
( |
input |
( |
columns_names |
( |
plot_var |
( |
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 |
( |
parent_dataname |
( |
output |
( |
data |
( |
input |
( |
columns_names |
( |
plot_var |
( |
Subset decorators based on the scope
Description
Subset decorators based on the scope
Usage
select_decorators(decorators, scope)
Arguments
decorators |
(named |
scope |
( |
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 |
( |
plot_width |
( |
rotate_xaxis_labels |
( |
ggtheme |
( |
ggplot2_args |
( For more details see the vignette: |
basic_table_args |
( For more details see the vignette: |
pre_output |
( |
post_output |
( |
alpha |
(
|
size |
(
|
decorators |
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 |
( |
data |
( |
expr |
( |
expr_is_reactive |
( |
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 |
( |
dat |
( |
plot_height |
( |
plot_width |
( |
ggtheme |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
rotate_xaxis_labels |
( |
font_size |
(
|
alpha |
(
|
size |
(
|
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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:
-
elbow_plot
(ggplot
) -
circle_plot
(ggplot
) -
biplot
(ggplot
) -
eigenvector_plot
(ggplot
)
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
- example-2
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 |
( |
regressor |
( |
response |
( |
plot_height |
( |
plot_width |
( |
alpha |
(
|
size |
(
|
ggtheme |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
pre_output |
( |
post_output |
( |
default_plot_type |
(
|
default_outlier_label |
( |
label_segment_threshold |
( It can take the following forms:
|
transformators |
( |
decorators |
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:
-
plot
(ggplot
)
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
- example-2
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.frame
s 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 |
( |
variables_selected |
( |
datasets_selected |
( |
datanames |
(
|
dt_args |
( |
dt_options |
( |
server_rendering |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
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
- example-2
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 |
( |
input_path |
( 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
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
Value
Object of class teal_module
to be used in teal
applications.
Examples in Shinylive
- example-1
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 |
( |
ref |
( |
vars |
( |
show_association |
( |
plot_height |
( |
plot_width |
( |
distribution_theme , association_theme |
( |
pre_output |
( |
post_output |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
transformators |
( |
decorators |
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:
-
plot
(grob
created withggplot2::ggplotGrob()
)
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
- example-2
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 |
( |
x |
( |
y |
( |
row_facet |
( |
col_facet |
( |
facet |
( |
color |
( |
fill |
( |
size |
( |
use_density |
( |
color_settings |
( |
free_x_scales |
( |
free_y_scales |
( |
plot_height |
( |
plot_width |
( |
rotate_xaxis_labels |
( |
swap_axes |
( |
ggtheme |
( |
ggplot2_args |
( For more details see the vignette: |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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:
-
plot
(ggplot
)
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
- example-2
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 |
( |
dist_var |
( |
strata_var |
( |
group_var |
( |
freq |
( |
ggtheme |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
bins |
(
|
plot_height |
( |
plot_width |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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::
-
histogram_plot
(ggplot
) -
qq_plot
(ggplot
) -
summary_table
(datatables
created withDT::datatable()
) -
test_table
(datatables
created withDT::datatable()
)
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
- example-2
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 |
( |
response |
( The |
x |
( The |
row_facet |
( |
col_facet |
( |
coord_flip |
( |
count_labels |
( |
rotate_xaxis_labels |
( |
freq |
( |
plot_height |
( |
plot_width |
( |
ggtheme |
( |
ggplot2_args |
( For more details see the vignette: |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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:
-
plot
(ggplot
)
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
- example-2
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 |
( |
x |
( |
y |
( |
color_by |
( |
size_by |
( |
row_facet |
( |
col_facet |
( |
plot_height |
( |
plot_width |
( |
alpha |
(
|
shape |
( |
size |
(
|
max_deg |
( |
rotate_xaxis_labels |
( |
ggtheme |
( |
pre_output |
( |
post_output |
( |
table_dec |
( |
ggplot2_args |
( For more details see the vignette: |
transformators |
( |
decorators |
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:
-
plot
(ggplot
)
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
- example-2
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
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:
-
plot
(trellis
- output oflattice::splom
)
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
- example-2
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.frame
s 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 |
( |
plot_height |
( |
plot_width |
( |
datanames |
(
|
parent_dataname |
( |
ggtheme |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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:
-
summary_plot
(grob
created withggplot2::ggplotGrob()
) -
combination_plot
(grob
created withggplot2::ggplotGrob()
) -
by_subject_plot
(ggplot
) -
table
(datatables
created withDT::datatable()
)
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
- example-2
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 |
( |
outlier_var |
( |
categorical_var |
( |
ggtheme |
( |
ggplot2_args |
( List names should match the following: For more details see the vignette: |
plot_height |
( |
plot_width |
( |
pre_output |
( |
post_output |
( |
transformators |
( |
decorators |
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:
-
box_plot
(ggplot
) -
density_plot
(ggplot
) -
cumulative_plot
(ggplot
) -
table
(datatables
created withDT::datatable()
)
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
- example-2
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 |
( |
x |
( |
y |
(
|
show_percentage |
( |
show_total |
( |
pre_output |
( |
post_output |
( |
basic_table_args |
( For more details see the vignette: |
transformators |
( |
decorators |
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:
-
table
(ElementaryTable
- output ofrtables::build_table
)
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
- example-2
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 |
( |
datasets_selected |
( |
datanames |
(
|
parent_dataname |
( |
pre_output |
( |
post_output |
( |
ggplot2_args |
( For more details see the vignette: |
transformators |
( |
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
- example-2
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 |
( |
plot_var |
( |
data |
( |
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 |
|
dt_rows |
|
outlier_definition |
If 0 no outliers are removed, otherwise
outliers (those more than |
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 |
( |
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 |
( |
dataset |
( |
wrap_width |
( |
prefix , suffix |
( |
Value
(character
) String with variable name and label.