Skip to content

Commit

Permalink
29 add non-cdisc examples to the modules (#651)
Browse files Browse the repository at this point in the history
Closes #29 

Added general data examples to modules.

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
chlebowa and github-actions[bot] authored Feb 22, 2024
1 parent 244d2fa commit 44ff2b1
Show file tree
Hide file tree
Showing 26 changed files with 1,628 additions and 451 deletions.
65 changes: 52 additions & 13 deletions R/tm_a_pca.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,84 @@
#' @templateVar ggnames "Elbow plot", "Circle plot", "Biplot", "Eigenvector plot"
#' @template ggplot2_args_multi
#'
#' @export
#'
#' @examples
#' # general data example
#' library(teal.widgets)
#'
#' # ADSL example
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' USArrests <- USArrests
#' })
#' datanames(data) <- "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
#' ),
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by PCA Module")
#' )
#' )
#' )
#' )
#'
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' # CDISC data example
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- teal.modules.general::rADSL
#' ADSL <- rADSL
#' })
#' datanames <- c("ADSL")
#' datanames(data) <- datanames
#' join_keys(data) <- default_cdisc_join_keys[datanames]
#' app <- teal::init(
#' datanames(data) <- "ADSL"
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = data,
#' modules = teal::modules(
#' modules = modules(
#' teal.modules.general::tm_a_pca(
#' "PCA",
#' dat = teal.transform::data_extract_spec(
#' dat = data_extract_spec(
#' dataname = "ADSL",
#' select = teal.transform::select_spec(
#' choices = teal.transform::variable_choices(
#' select = select_spec(
#' choices = variable_choices(
#' data = data[["ADSL"]], c("BMRKR1", "AGE", "EOSDY")
#' ),
#' selected = c("BMRKR1", "AGE"),
#' multiple = TRUE
#' ),
#' filter = NULL
#' ),
#' ggplot2_args = teal.widgets::ggplot2_args(
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by PCA Module")
#' )
#' )
#' )
#' )
#'
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' @export
#'
tm_a_pca <- function(label = "Principal Component Analysis",
dat,
plot_height = c(600, 200, 2000),
Expand Down
78 changes: 62 additions & 16 deletions R/tm_a_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,47 +28,90 @@
#'
#' @note For more examples, please see the vignette "Using regression plots" via
#' `vignette("using-regression-plots", package = "teal.modules.general")`.
#' @export
#'
#' @examples
#' # Regression graphs from selected response variable (BMRKR1) and
#' # selected regressors (AGE)
#' # general data example
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- teal.modules.general::rADSL
#' CO2 <- CO2
#' })
#' datanames <- c("ADSL")
#' datanames(data) <- datanames
#' join_keys(data) <- default_cdisc_join_keys[datanames]
#' datanames(data) <- c("CO2")
#'
#' app <- teal::init(
#' app <- init(
#' data = data,
#' modules = teal::modules(
#' teal.modules.general::tm_a_regression(
#' modules = modules(
#' tm_a_regression(
#' label = "Regression",
#' response = teal.transform::data_extract_spec(
#' 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
#' )
#' ),
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by Regression Module")
#' )
#' )
#' )
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' # CDISC data example
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- rADSL
#' })
#' datanames(data) <- "ADSL"
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = data,
#' modules = modules(
#' tm_a_regression(
#' label = "Regression",
#' response = data_extract_spec(
#' dataname = "ADSL",
#' select = teal.transform::select_spec(
#' select = select_spec(
#' label = "Select variable:",
#' choices = "BMRKR1",
#' selected = "BMRKR1",
#' multiple = FALSE,
#' fixed = TRUE
#' )
#' ),
#' regressor = teal.transform::data_extract_spec(
#' regressor = data_extract_spec(
#' dataname = "ADSL",
#' select = teal.transform::select_spec(
#' select = select_spec(
#' label = "Select variables:",
#' choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")),
#' choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE")),
#' selected = "AGE",
#' multiple = TRUE,
#' fixed = FALSE
#' )
#' ),
#' ggplot2_args = teal.widgets::ggplot2_args(
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by Regression Module")
#' )
#' )
Expand All @@ -77,6 +120,9 @@
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' @export
#'
tm_a_regression <- function(label = "Regression Analysis",
regressor,
response,
Expand Down
42 changes: 34 additions & 8 deletions R/tm_data_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,45 @@
#' The `DT` package has an option `DT.TOJSON_ARGS` to show `Inf` and `NA` in data tables. If this is something
#' you require then set `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.
#' @export
#'
#' @examples
#' # general data example
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- teal.modules.general::rADSL
#' iris <- iris
#' })
#' datanames <- c("ADSL")
#' datanames(data) <- datanames
#' join_keys(data) <- default_cdisc_join_keys[datanames]
#' datanames(data) <- c("iris")
#'
#' app <- teal::init(
#' app <- init(
#' data = data,
#' modules = teal::modules(
#' teal.modules.general::tm_data_table(
#' modules = modules(
#' tm_data_table(
#' variables_selected = list(
#' iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
#' ),
#' dt_args = list(caption = "ADSL Table Caption")
#' )
#' )
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' # CDISC data example
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- rADSL
#' })
#' datanames(data) <- "ADSL"
#' join_keys(data) <- default_cdisc_join_keys[datanames(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")
#' )
Expand All @@ -49,6 +72,9 @@
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' @export
#'
tm_data_table <- function(label = "Data Table",
variables_selected = list(),
datasets_selected = character(0),
Expand Down
82 changes: 65 additions & 17 deletions R/tm_g_association.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,85 @@
#'
#' @note For more examples, please see the vignette "Using association plot" via
#' \code{vignette("using-association-plot", package = "teal.modules.general")}.
#' @export
#'
#' @examples
#' # Association plot of selected reference variable (SEX)
#' # against other selected variables (BMRKR1)
#' # general data exapmle
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- teal.modules.general::rADSL
#' CO2 <- CO2
#' factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L))))
#' CO2[factors] <- lapply(CO2[factors], as.character)
#' })
#' datanames <- c("ADSL")
#' datanames(data) <- datanames
#' join_keys(data) <- default_cdisc_join_keys[datanames]
#' datanames(data) <- c("CO2")
#'
#' app <- teal::init(
#' app <- init(
#' data = data,
#' modules = teal::modules(
#' teal.modules.general::tm_g_association(
#' ref = teal.transform::data_extract_spec(
#' 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
#' )
#' ),
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by Association Module")
#' )
#' )
#' )
#' )
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' # CDISC data example
#' library(teal.widgets)
#'
#' data <- teal_data()
#' data <- within(data, {
#' library(nestcolor)
#' ADSL <- rADSL
#' })
#' datanames(data) <- "ADSL"
#' join_keys(data) <- default_cdisc_join_keys[datanames(data)]
#'
#' app <- init(
#' data = data,
#' modules = modules(
#' tm_g_association(
#' ref = data_extract_spec(
#' dataname = "ADSL",
#' select = teal.transform::select_spec(
#' select = select_spec(
#' label = "Select variable:",
#' choices = teal.transform::variable_choices(
#' choices = variable_choices(
#' data[["ADSL"]],
#' c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2")
#' ),
#' selected = "RACE",
#' fixed = FALSE
#' )
#' ),
#' vars = teal.transform::data_extract_spec(
#' vars = data_extract_spec(
#' dataname = "ADSL",
#' select = teal.transform::select_spec(
#' select = select_spec(
#' label = "Select variables:",
#' choices = teal.transform::variable_choices(
#' choices = variable_choices(
#' data[["ADSL"]],
#' c("SEX", "RACE", "COUNTRY", "ARM", "STRATA1", "STRATA2", "ITTFL", "BMRKR2")
#' ),
Expand All @@ -59,7 +104,7 @@
#' fixed = FALSE
#' )
#' ),
#' ggplot2_args = teal.widgets::ggplot2_args(
#' ggplot2_args = ggplot2_args(
#' labs = list(subtitle = "Plot generated by Association Module")
#' )
#' )
Expand All @@ -68,6 +113,9 @@
#' if (interactive()) {
#' shinyApp(app$ui, app$server)
#' }
#'
#' @export
#'
tm_g_association <- function(label = "Association",
ref,
vars,
Expand Down
Loading

0 comments on commit 44ff2b1

Please sign in to comment.