diff --git a/R/tm_a_pca.R b/R/tm_a_pca.R index 74eb8ebb5..5fd0400b5 100644 --- a/R/tm_a_pca.R +++ b/R/tm_a_pca.R @@ -18,29 +18,64 @@ #' @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"), @@ -48,15 +83,19 @@ #' ), #' 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), diff --git a/R/tm_a_regression.R b/R/tm_a_regression.R index d82a17639..fbf45f765 100644 --- a/R/tm_a_regression.R +++ b/R/tm_a_regression.R @@ -28,29 +28,72 @@ #' #' @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", @@ -58,17 +101,17 @@ #' 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") #' ) #' ) @@ -77,6 +120,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_a_regression <- function(label = "Regression Analysis", regressor, response, diff --git a/R/tm_data_table.R b/R/tm_data_table.R index 29adb0212..770d6cfa2 100644 --- a/R/tm_data_table.R +++ b/R/tm_data_table.R @@ -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") #' ) @@ -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), diff --git a/R/tm_g_association.R b/R/tm_g_association.R index 43b37062b..9004fe84f 100644 --- a/R/tm_g_association.R +++ b/R/tm_g_association.R @@ -17,28 +17,73 @@ #' #' @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") #' ), @@ -46,11 +91,11 @@ #' 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") #' ), @@ -59,7 +104,7 @@ #' fixed = FALSE #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Association Module") #' ) #' ) @@ -68,6 +113,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_g_association <- function(label = "Association", ref, vars, diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 460ba1b9c..88241f479 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -44,58 +44,122 @@ #' @export #' #' @examples -#' # Bivariate plot of selected variable (AGE) against selected (SEX) +#' # general data exapmle +#' library(teal.widgets) +#' +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' CO2 <- data.frame(CO2) +#' }) +#' datanames(data) <- c("CO2") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] +#' +#' app <- init( +#' data = data, +#' modules = 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 +#' ) +#' ), +#' ggplot2_args = ggplot2_args( +#' labs = list(subtitle = "Plot generated by Bivariate 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] +#' datanames(data) <- c("ADSL") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_g_bivariate( -#' x = teal.transform::data_extract_spec( +#' modules = modules( +#' tm_g_bivariate( +#' x = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]]), +#' choices = variable_choices(data[["ADSL"]]), #' selected = "AGE", #' fixed = FALSE #' ) #' ), -#' y = teal.transform::data_extract_spec( +#' y = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]]), +#' choices = variable_choices(data[["ADSL"]]), #' selected = "SEX", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' row_facet = teal.transform::data_extract_spec( +#' row_facet = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]]), +#' choices = variable_choices(data[["ADSL"]]), #' selected = "ARM", #' fixed = FALSE #' ) #' ), -#' col_facet = teal.transform::data_extract_spec( +#' col_facet = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]]), +#' choices = variable_choices(data[["ADSL"]]), #' selected = "COUNTRY", #' fixed = FALSE #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Bivariate Module") #' ) #' ) diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index 48a0adef4..8b603ec62 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -24,27 +24,25 @@ #' @templateVar ggnames "Histogram", "QQplot" #' @template ggplot2_args_multi #' -#' -#' @export -#' #' @examples -#' # Example with non-clinical data +#' # general data example +#' library(teal.widgets) #' #' data <- teal_data() #' data <- within(data, { #' iris <- iris #' }) -#' datanames(data) <- c("iris") +#' datanames(data) <- "iris" #' -#' app <- teal::init( +#' app <- init( #' data = data, #' modules = list( -#' teal.modules.general::tm_g_distribution( -#' dist_var = teal.transform::data_extract_spec( +#' tm_g_distribution( +#' dist_var = data_extract_spec( #' dataname = "iris", -#' select = teal.transform::select_spec(variable_choices("iris"), "Petal.Length") +#' select = select_spec(variable_choices("iris"), "Petal.Length") #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Distribution Module") #' ) #' ) @@ -54,48 +52,49 @@ #' shinyApp(app$ui, app$server) #' } #' -#' # Example with clinical data +#' # CDISC data example +#' library(teal.widgets) +#' #' data <- teal_data() #' data <- within(data, { -#' ADSL <- teal.modules.general::rADSL +#' ADSL <- rADSL #' }) -#' datanames <- c("ADSL") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- c("ADSL") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' #' vars1 <- choices_selected( #' variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), #' selected = NULL #' ) #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_g_distribution( -#' dist_var = teal.transform::data_extract_spec( +#' modules = modules( +#' tm_g_distribution( +#' dist_var = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( -#' choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), +#' select = select_spec( +#' choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), #' selected = "BMRKR1", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' strata_var = teal.transform::data_extract_spec( +#' strata_var = data_extract_spec( #' dataname = "ADSL", -#' filter = teal.transform::filter_spec( +#' filter = filter_spec( #' vars = vars1, #' multiple = TRUE #' ) #' ), -#' group_var = teal.transform::data_extract_spec( +#' group_var = data_extract_spec( #' dataname = "ADSL", -#' filter = teal.transform::filter_spec( +#' filter = filter_spec( #' vars = vars1, #' multiple = TRUE #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Distribution Module") #' ) #' ) @@ -104,6 +103,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_g_distribution <- function(label = "Distribution Module", dist_var, strata_var = NULL, diff --git a/R/tm_g_response.R b/R/tm_g_response.R index 3ca9acdf0..692f25487 100644 --- a/R/tm_g_response.R +++ b/R/tm_g_response.R @@ -23,45 +23,93 @@ #' #' @note For more examples, please see the vignette "Using response plot" via #' \code{vignette("using-response-plot", package = "teal.modules.general")}. -#' @export +#' #' @examples -#' # Response plot with selected response (BMRKR1) and selected x variable (RACE) +#' # general data example +#' library(teal.widgets) +#' +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' mtcars <- mtcars +#' for (v in c("cyl", "vs", "am", "gear")) { +#' mtcars[[v]] <- as.factor(mtcars[[v]]) +#' } +#' }) +#' datanames(data) <- "mtcars" +#' +#' 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 +#' ) +#' ), +#' ggplot2_args = ggplot2_args( +#' labs = list(subtitle = "Plot generated by Response 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] +#' datanames(data) <- c("ADSL") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_g_response( +#' modules = modules( +#' tm_g_response( #' label = "Response Plots", -#' response = teal.transform::data_extract_spec( +#' response = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), +#' choices = variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), #' selected = "BMRKR2", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' x = teal.transform::data_extract_spec( +#' x = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices(data[["ADSL"]], c("SEX", "RACE")), +#' choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")), #' selected = "RACE", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Response Module") #' ) #' ) @@ -70,6 +118,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_g_response <- function(label = "Response Plot", response, x, diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index 9caab3f2c..f42c27445 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -33,55 +33,137 @@ #' @note For more examples, please see the vignette "Using scatterplot" via #' `vignette("using-scatterplot", package = "teal.modules.general")`. #' -#' @export #' @examples -#' # Scatterplot of variables from ADSL dataset +#' # 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) <- "CO2" #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_g_scatterplot( +#' modules = modules( +#' tm_g_scatterplot( #' label = "Scatterplot Choices", -#' x = teal.transform::data_extract_spec( -#' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' x = data_extract_spec( +#' dataname = "CO2", +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices( -#' data[["ADSL"]], -#' c("AGE", "BMRKR1", "BMRKR2") +#' 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 +#' ) +#' ), +#' ggplot2_args = ggplot2_args( +#' labs = list(subtitle = "Plot generated by Scatterplot 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) <- c("ADSL") +#' join_keys(data) <- default_cdisc_join_keys[datanames(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 = teal.transform::data_extract_spec( +#' y = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices( -#' data[["ADSL"]], -#' c("AGE", "BMRKR1", "BMRKR2") -#' ), +#' choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), #' selected = "BMRKR1", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' color_by = teal.transform::data_extract_spec( +#' color_by = 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("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") #' ), @@ -90,46 +172,37 @@ #' fixed = FALSE #' ) #' ), -#' size_by = teal.transform::data_extract_spec( +#' size_by = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices( -#' data[["ADSL"]], -#' c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") -#' ), +#' choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), #' selected = "AGE", #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' row_facet = teal.transform::data_extract_spec( +#' row_facet = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices( -#' data[["ADSL"]], -#' c("BMRKR2", "RACE", "REGION1") -#' ), +#' choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), #' selected = NULL, #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' col_facet = teal.transform::data_extract_spec( +#' col_facet = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", -#' choices = teal.transform::variable_choices( -#' data[["ADSL"]], -#' c("BMRKR2", "RACE", "REGION1") -#' ), +#' choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), #' selected = NULL, #' multiple = FALSE, #' fixed = FALSE #' ) #' ), -#' ggplot2_args = teal.widgets::ggplot2_args( +#' ggplot2_args = ggplot2_args( #' labs = list(subtitle = "Plot generated by Scatterplot Module") #' ) #' ) @@ -138,6 +211,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_g_scatterplot <- function(label = "Scatterplot", x, y, diff --git a/R/tm_g_scatterplotmatrix.R b/R/tm_g_scatterplotmatrix.R index b82e1d41d..6f740f032 100644 --- a/R/tm_g_scatterplotmatrix.R +++ b/R/tm_g_scatterplotmatrix.R @@ -15,27 +15,107 @@ #' #' @note For more examples, please see the vignette "Using scatterplot matrix" via #' \code{vignette("using-scatterplot-matrix", package = "teal.modules.general")}. -#' @export #' #' @examples -#' # Scatterplot matrix of variables from ADSL dataset +#' # 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) +#' ) +#' }) +#' datanames(data) <- c("countries", "sales") +#' 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", "ES", "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.modules.general::rADSL -#' ADRS <- teal.modules.general::rADRS +#' ADSL <- rADSL +#' ADRS <- rADRS #' }) -#' datanames <- c("ADSL", "ADRS") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- c("ADSL", "ADRS") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_g_scatterplotmatrix( +#' modules = modules( +#' tm_g_scatterplotmatrix( #' label = "Scatterplot matrix", #' variables = list( -#' teal.transform::data_extract_spec( +#' data_extract_spec( #' dataname = "ADSL", #' select = select_spec( #' label = "Select variables:", @@ -46,9 +126,9 @@ #' fixed = FALSE #' ) #' ), -#' teal.transform::data_extract_spec( +#' data_extract_spec( #' dataname = "ADRS", -#' filter = teal.transform::filter_spec( +#' filter = filter_spec( #' label = "Select endpoints:", #' vars = c("PARAMCD", "AVISIT"), #' choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), @@ -71,6 +151,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_g_scatterplotmatrix <- function(label = "Scatterplot Matrix", variables, plot_height = c(600, 200, 2000), diff --git a/R/tm_missing_data.R b/R/tm_missing_data.R index 64a81c968..d6b8d02f1 100644 --- a/R/tm_missing_data.R +++ b/R/tm_missing_data.R @@ -12,36 +12,67 @@ #' @templateVar ggnames "Summary Obs", "Summary Patients", "Combinations Main", "Combinations Hist", "By Subject" #' @template ggplot2_args_multi #' -#' @export -#' #' @examples +#' library(teal.widgets) +#' +#' # module specification used in apps below +#' tm_missing_data_module <- tm_missing_data( +#' ggplot2_args = list( +#' "Combinations Hist" = ggplot2_args( +#' labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL) +#' ), +#' "Combinations Main" = ggplot2_args(labs = list(title = NULL)) +#' ) +#' ) #' +#' # general example data #' data <- teal_data() #' data <- within(data, { #' library(nestcolor) -#' ADSL <- teal.modules.general::rADSL -#' ADRS <- teal.modules.general::rADRS +#' +#' 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"]]) #' }) -#' datanames <- c("ADSL", "ADRS") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- c("iris", "mtcars") #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_missing_data( -#' ggplot2_args = list( -#' "Combinations Hist" = teal.widgets::ggplot2_args( -#' labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL) -#' ), -#' "Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL)) -#' ) -#' ) -#' ) +#' modules = modules(tm_missing_data_module) #' ) #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' # CDISC example data +#' data <- teal_data() +#' data <- within(data, { +#' library(nestcolor) +#' ADSL <- rADSL +#' ADRS <- rADRS +#' }) +#' datanames(data) <- c("ADSL", "ADRS") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] +#' +#' app <- init( +#' data = data, +#' modules = modules(tm_missing_data_module) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } +#' +#' @export +#' tm_missing_data <- function(label = "Missing data", plot_height = c(600, 400, 5000), plot_width = NULL, diff --git a/R/tm_outliers.R b/R/tm_outliers.R index e58d2c53f..a6fa14818 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -13,27 +13,78 @@ #' @templateVar ggnames "Boxplot","Density Plot","Cumulative Distribution Plot" #' @template ggplot2_args_multi #' -#' @export -#' #' @examples +#' # general data example +#' library(teal.widgets) #' #' data <- teal_data() #' data <- within(data, { -#' ADSL <- teal.modules.general::rADSL +#' CO2 <- CO2 +#' CO2[["primary_key"]] <- seq_len(nrow(CO2)) #' }) -#' datanames <- c("ADSL") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- "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 +#' ) +#' ) +#' ), +#' ggplot2_args = list( +#' ggplot2_args( +#' labs = list(subtitle = "Plot generated by Outliers Module") +#' ) +#' ) +#' ) +#' ) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } +#' +#' # CDISC data example +#' library(teal.widgets) +#' +#' data <- teal_data() +#' data <- within(data, { +#' ADSL <- rADSL +#' }) +#' datanames(data) <- "ADSL" +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' #' fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) #' vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_outliers( +#' modules = modules( +#' tm_outliers( #' outlier_var = list( -#' teal.transform::data_extract_spec( +#' data_extract_spec( #' dataname = "ADSL", #' select = select_spec( #' label = "Select variable:", @@ -45,9 +96,9 @@ #' ) #' ), #' categorical_var = list( -#' teal.transform::data_extract_spec( +#' data_extract_spec( #' dataname = "ADSL", -#' filter = teal.transform::filter_spec( +#' filter = filter_spec( #' vars = vars, #' choices = value_choices(data[["ADSL"]], vars$selected), #' selected = value_choices(data[["ADSL"]], vars$selected), @@ -56,7 +107,7 @@ #' ) #' ), #' ggplot2_args = list( -#' teal.widgets::ggplot2_args( +#' ggplot2_args( #' labs = list(subtitle = "Plot generated by Outliers Module") #' ) #' ) @@ -66,6 +117,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_outliers <- function(label = "Outliers Module", outlier_var, categorical_var = NULL, diff --git a/R/tm_t_crosstable.R b/R/tm_t_crosstable.R index 809956335..fad85693b 100644 --- a/R/tm_t_crosstable.R +++ b/R/tm_t_crosstable.R @@ -18,27 +18,75 @@ #' @note For more examples, please see the vignette "Using cross table" via #' `vignette("using-cross-table", package = "teal.modules.general")`. #' -#' @export -#' #' @examples -#' # Percentage cross table of variables from ADSL dataset +#' # general data example +#' library(teal.widgets) +#' +#' 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)) +#' }) +#' datanames(data) <- "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 +#' ) +#' ), +#' basic_table_args = basic_table_args( +#' subtitles = "Table generated by Crosstable Module" +#' ) +#' ) +#' ) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } +#' +#' # CDISC data example +#' library(teal.widgets) #' #' data <- teal_data() #' data <- within(data, { -#' ADSL <- teal.modules.general::rADSL +#' ADSL <- rADSL #' }) -#' datanames <- c("ADSL") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- "ADSL" +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules = teal::modules( -#' teal.modules.general::tm_t_crosstable( +#' modules = modules( +#' tm_t_crosstable( #' label = "Cross Table", -#' x = teal.transform::data_extract_spec( +#' x = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", #' choices = variable_choices(data[["ADSL"]], subset = function(data) { #' idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt")) @@ -50,9 +98,9 @@ #' fixed = FALSE #' ) #' ), -#' y = teal.transform::data_extract_spec( +#' y = data_extract_spec( #' dataname = "ADSL", -#' select = teal.transform::select_spec( +#' select = select_spec( #' label = "Select variable:", #' choices = variable_choices(data[["ADSL"]], subset = function(data) { #' idx <- vapply(data, is.factor, logical(1)) @@ -63,7 +111,7 @@ #' fixed = FALSE #' ) #' ), -#' basic_table_args = teal.widgets::basic_table_args( +#' basic_table_args = basic_table_args( #' subtitles = "Table generated by Crosstable Module" #' ) #' ) @@ -72,6 +120,9 @@ #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_t_crosstable <- function(label = "Cross Table", x, y, diff --git a/R/tm_variable_browser.R b/R/tm_variable_browser.R index 71730bff8..40de67976 100644 --- a/R/tm_variable_browser.R +++ b/R/tm_variable_browser.R @@ -28,34 +28,55 @@ #' variable_browser_srv, #' variable_browser #' +#' @examples +#' library(teal.widgets) #' -#' @export +#' # module specification used in apps below +#' tm_variable_browser_module <- tm_variable_browser( +#' label = "Variable browser", +#' ggplot2_args = ggplot2_args( +#' labs = list(subtitle = "Plot generated by Variable Browser Module") +#' ) +#' ) #' -#' @examples +#' # general data example +#' data <- teal_data() +#' data <- within(data, { +#' iris <- iris +#' mtcars <- mtcars +#' women <- women +#' faithful <- faithful +#' CO2 <- CO2 +#' }) +#' datanames(data) <- c("iris", "mtcars", "women", "faithful", "CO2") +#' +#' app <- init( +#' data = data, +#' modules = modules(tm_variable_browser_module) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } #' +#' # CDISC example data #' data <- teal_data() #' data <- within(data, { -#' ADSL <- teal.modules.general::rADSL -#' ADTTE <- teal.modules.general::rADTTE +#' ADSL <- rADSL +#' ADTTE <- rADTTE #' }) -#' datanames <- c("ADSL", "ADTTE") -#' datanames(data) <- datanames -#' join_keys(data) <- default_cdisc_join_keys[datanames] +#' datanames(data) <- c("ADSL", "ADTTE") +#' join_keys(data) <- default_cdisc_join_keys[datanames(data)] #' -#' app <- teal::init( +#' app <- init( #' data = data, -#' modules( -#' teal.modules.general::tm_variable_browser( -#' label = "Variable browser", -#' ggplot2_args = teal.widgets::ggplot2_args( -#' labs = list(subtitle = "Plot generated by Variable Browser Module") -#' ), -#' ) -#' ) +#' modules = modules(tm_variable_browser_module) #' ) #' if (interactive()) { #' shinyApp(app$ui, app$server) #' } +#' +#' @export +#' tm_variable_browser <- function(label = "Variable Browser", datasets_selected = character(0), parent_dataname = "ADSL", diff --git a/man/tm_a_pca.Rd b/man/tm_a_pca.Rd index e01bdbe27..0242a7910 100644 --- a/man/tm_a_pca.Rd +++ b/man/tm_a_pca.Rd @@ -67,26 +67,63 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el Principal component analysis module } \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"), @@ -94,13 +131,15 @@ app <- teal::init( ), 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) } + } diff --git a/man/tm_a_regression.Rd b/man/tm_a_regression.Rd index a52ea262c..8777542a4 100644 --- a/man/tm_a_regression.Rd +++ b/man/tm_a_regression.Rd @@ -81,26 +81,70 @@ For more examples, please see the vignette "Using regression plots" via \code{vignette("using-regression-plots", package = "teal.modules.general")}. } \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", @@ -108,17 +152,17 @@ app <- teal::init( 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") ) ) @@ -127,4 +171,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_data_table.Rd b/man/tm_data_table.Rd index bec8cde63..ab6e5ad09 100644 --- a/man/tm_data_table.Rd +++ b/man/tm_data_table.Rd @@ -56,20 +56,43 @@ you require then set \code{options(DT.TOJSON_ARGS = list(na = "string"))} befor Note though that sorting of numeric columns with \code{NA}/\code{Inf} will be lexicographic not numerical. } \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") ) @@ -78,4 +101,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_g_association.Rd b/man/tm_g_association.Rd index 321d1d175..d5182e335 100644 --- a/man/tm_g_association.Rd +++ b/man/tm_g_association.Rd @@ -64,26 +64,71 @@ For more examples, please see the vignette "Using association plot" via \code{vignette("using-association-plot", package = "teal.modules.general")}. } \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") ), @@ -91,11 +136,11 @@ app <- teal::init( 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") ), @@ -104,7 +149,7 @@ app <- teal::init( fixed = FALSE ) ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Association Module") ) ) @@ -113,4 +158,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_g_bivariate.Rd b/man/tm_g_bivariate.Rd index 12a90c52f..f1d0398d6 100644 --- a/man/tm_g_bivariate.Rd +++ b/man/tm_g_bivariate.Rd @@ -109,58 +109,122 @@ For more examples, please see the vignette "Using bivariate plot" via \code{vignette("using-bivariate-plot", package = "teal.modules.general")}. } \examples{ -# Bivariate plot of selected variable (AGE) against selected (SEX) +# general data exapmle +library(teal.widgets) + +data <- teal_data() +data <- within(data, { + library(nestcolor) + CO2 <- data.frame(CO2) +}) +datanames(data) <- c("CO2") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] + +app <- init( + data = data, + modules = 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 + ) + ), + ggplot2_args = ggplot2_args( + labs = list(subtitle = "Plot generated by Bivariate 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] +datanames(data) <- c("ADSL") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_g_bivariate( - x = teal.transform::data_extract_spec( + modules = modules( + tm_g_bivariate( + x = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]]), + choices = variable_choices(data[["ADSL"]]), selected = "AGE", fixed = FALSE ) ), - y = teal.transform::data_extract_spec( + y = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]]), + choices = variable_choices(data[["ADSL"]]), selected = "SEX", multiple = FALSE, fixed = FALSE ) ), - row_facet = teal.transform::data_extract_spec( + row_facet = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]]), + choices = variable_choices(data[["ADSL"]]), selected = "ARM", fixed = FALSE ) ), - col_facet = teal.transform::data_extract_spec( + col_facet = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]]), + choices = variable_choices(data[["ADSL"]]), selected = "COUNTRY", fixed = FALSE ) ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Bivariate Module") ) ) diff --git a/man/tm_g_distribution.Rd b/man/tm_g_distribution.Rd index a82403274..a359f7333 100644 --- a/man/tm_g_distribution.Rd +++ b/man/tm_g_distribution.Rd @@ -69,23 +69,24 @@ Distribution Module Module to analyze and explore univariate variable distribution } \examples{ -# Example with non-clinical data +# general data example +library(teal.widgets) data <- teal_data() data <- within(data, { iris <- iris }) -datanames(data) <- c("iris") +datanames(data) <- "iris" -app <- teal::init( +app <- init( data = data, modules = list( - teal.modules.general::tm_g_distribution( - dist_var = teal.transform::data_extract_spec( + tm_g_distribution( + dist_var = data_extract_spec( dataname = "iris", - select = teal.transform::select_spec(variable_choices("iris"), "Petal.Length") + select = select_spec(variable_choices("iris"), "Petal.Length") ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Distribution Module") ) ) @@ -95,48 +96,49 @@ if (interactive()) { shinyApp(app$ui, app$server) } -# Example with clinical data +# CDISC data example +library(teal.widgets) + data <- teal_data() data <- within(data, { - ADSL <- teal.modules.general::rADSL + ADSL <- rADSL }) -datanames <- c("ADSL") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- c("ADSL") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] vars1 <- choices_selected( variable_choices(data[["ADSL"]], c("ARM", "COUNTRY", "SEX")), selected = NULL ) -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_g_distribution( - dist_var = teal.transform::data_extract_spec( + modules = modules( + tm_g_distribution( + dist_var = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( - choices = teal.transform::variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), + select = select_spec( + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), - strata_var = teal.transform::data_extract_spec( + strata_var = data_extract_spec( dataname = "ADSL", - filter = teal.transform::filter_spec( + filter = filter_spec( vars = vars1, multiple = TRUE ) ), - group_var = teal.transform::data_extract_spec( + group_var = data_extract_spec( dataname = "ADSL", - filter = teal.transform::filter_spec( + filter = filter_spec( vars = vars1, multiple = TRUE ) ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Distribution Module") ) ) @@ -145,4 +147,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_g_response.Rd b/man/tm_g_response.Rd index 6d0986c2f..71d994bb6 100644 --- a/man/tm_g_response.Rd +++ b/man/tm_g_response.Rd @@ -81,43 +81,91 @@ For more examples, please see the vignette "Using response plot" via \code{vignette("using-response-plot", package = "teal.modules.general")}. } \examples{ -# Response plot with selected response (BMRKR1) and selected x variable (RACE) +# general data example +library(teal.widgets) data <- teal_data() data <- within(data, { library(nestcolor) - ADSL <- teal.modules.general::rADSL + mtcars <- mtcars + for (v in c("cyl", "vs", "am", "gear")) { + mtcars[[v]] <- as.factor(mtcars[[v]]) + } }) -datanames <- c("ADSL") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- "mtcars" -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_g_response( + modules = modules( + tm_g_response( label = "Response Plots", - response = teal.transform::data_extract_spec( + 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 + ) + ), + ggplot2_args = ggplot2_args( + labs = list(subtitle = "Plot generated by Response 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) <- c("ADSL") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] + +app <- init( + data = data, + modules = modules( + tm_g_response( + label = "Response Plots", + response = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), + choices = variable_choices(data[["ADSL"]], c("BMRKR2", "COUNTRY")), selected = "BMRKR2", multiple = FALSE, fixed = FALSE ) ), - x = teal.transform::data_extract_spec( + x = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices(data[["ADSL"]], c("SEX", "RACE")), + choices = variable_choices(data[["ADSL"]], c("SEX", "RACE")), selected = "RACE", multiple = FALSE, fixed = FALSE ) ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Response Module") ) ) @@ -126,4 +174,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_g_scatterplot.Rd b/man/tm_g_scatterplot.Rd index 1c742cac2..16d14c6b0 100644 --- a/man/tm_g_scatterplot.Rd +++ b/man/tm_g_scatterplot.Rd @@ -95,53 +95,136 @@ For more examples, please see the vignette "Using scatterplot" via \code{vignette("using-scatterplot", package = "teal.modules.general")}. } \examples{ -# Scatterplot of variables from ADSL dataset +# 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) <- "CO2" -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_g_scatterplot( + modules = modules( + tm_g_scatterplot( label = "Scatterplot Choices", - x = teal.transform::data_extract_spec( - dataname = "ADSL", - select = teal.transform::select_spec( + x = data_extract_spec( + dataname = "CO2", + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices( - data[["ADSL"]], - c("AGE", "BMRKR1", "BMRKR2") + 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 + ) + ), + ggplot2_args = ggplot2_args( + labs = list(subtitle = "Plot generated by Scatterplot 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) <- c("ADSL") +join_keys(data) <- default_cdisc_join_keys[datanames(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 = teal.transform::data_extract_spec( + y = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices( - data[["ADSL"]], - c("AGE", "BMRKR1", "BMRKR2") - ), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1", "BMRKR2")), selected = "BMRKR1", multiple = FALSE, fixed = FALSE ) ), - color_by = teal.transform::data_extract_spec( + color_by = 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("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") ), @@ -150,46 +233,37 @@ app <- teal::init( fixed = FALSE ) ), - size_by = teal.transform::data_extract_spec( + size_by = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices( - data[["ADSL"]], - c("AGE", "BMRKR1", "BMRKR2", "RACE", "REGION1") - ), + choices = variable_choices(data[["ADSL"]], c("AGE", "BMRKR1")), selected = "AGE", multiple = FALSE, fixed = FALSE ) ), - row_facet = teal.transform::data_extract_spec( + row_facet = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices( - data[["ADSL"]], - c("BMRKR2", "RACE", "REGION1") - ), + choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), - col_facet = teal.transform::data_extract_spec( + col_facet = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", - choices = teal.transform::variable_choices( - data[["ADSL"]], - c("BMRKR2", "RACE", "REGION1") - ), + choices = variable_choices(data[["ADSL"]], c("BMRKR2", "RACE", "REGION1")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), - ggplot2_args = teal.widgets::ggplot2_args( + ggplot2_args = ggplot2_args( labs = list(subtitle = "Plot generated by Scatterplot Module") ) ) @@ -198,4 +272,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_g_scatterplotmatrix.Rd b/man/tm_g_scatterplotmatrix.Rd index 0bc3b8782..071175f9d 100644 --- a/man/tm_g_scatterplotmatrix.Rd +++ b/man/tm_g_scatterplotmatrix.Rd @@ -43,24 +43,105 @@ For more examples, please see the vignette "Using scatterplot matrix" via \code{vignette("using-scatterplot-matrix", package = "teal.modules.general")}. } \examples{ -# Scatterplot matrix of variables from ADSL dataset +# 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) + ) +}) +datanames(data) <- c("countries", "sales") +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", "ES", "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.modules.general::rADSL - ADRS <- teal.modules.general::rADRS + ADSL <- rADSL + ADRS <- rADRS }) -datanames <- c("ADSL", "ADRS") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- c("ADSL", "ADRS") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_g_scatterplotmatrix( + modules = modules( + tm_g_scatterplotmatrix( label = "Scatterplot matrix", variables = list( - teal.transform::data_extract_spec( + data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variables:", @@ -71,9 +152,9 @@ app <- teal::init( fixed = FALSE ) ), - teal.transform::data_extract_spec( + data_extract_spec( dataname = "ADRS", - filter = teal.transform::filter_spec( + filter = filter_spec( label = "Select endpoints:", vars = c("PARAMCD", "AVISIT"), choices = value_choices(data[["ADRS"]], c("PARAMCD", "AVISIT"), c("PARAM", "AVISIT")), @@ -96,4 +177,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_missing_data.Rd b/man/tm_missing_data.Rd index c8cc46e2e..9460399f5 100644 --- a/man/tm_missing_data.Rd +++ b/man/tm_missing_data.Rd @@ -51,31 +51,62 @@ Present analysis of missing observations and patients. specifically designed for use with \code{data.frames}. } \examples{ +library(teal.widgets) +# module specification used in apps below +tm_missing_data_module <- tm_missing_data( + ggplot2_args = list( + "Combinations Hist" = ggplot2_args( + labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL) + ), + "Combinations Main" = ggplot2_args(labs = list(title = NULL)) + ) +) + +# general example data data <- teal_data() data <- within(data, { library(nestcolor) - ADSL <- teal.modules.general::rADSL - ADRS <- teal.modules.general::rADRS + + 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"]]) }) -datanames <- c("ADSL", "ADRS") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- c("iris", "mtcars") -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_missing_data( - ggplot2_args = list( - "Combinations Hist" = teal.widgets::ggplot2_args( - labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL) - ), - "Combinations Main" = teal.widgets::ggplot2_args(labs = list(title = NULL)) - ) - ) - ) + modules = modules(tm_missing_data_module) ) if (interactive()) { shinyApp(app$ui, app$server) } + +# CDISC example data +data <- teal_data() +data <- within(data, { + library(nestcolor) + ADSL <- rADSL + ADRS <- rADRS +}) +datanames(data) <- c("ADSL", "ADRS") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] + +app <- init( + data = data, + modules = modules(tm_missing_data_module) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + } diff --git a/man/tm_outliers.Rd b/man/tm_outliers.Rd index 8c140e81d..d6efe45fa 100644 --- a/man/tm_outliers.Rd +++ b/man/tm_outliers.Rd @@ -52,24 +52,77 @@ into context. For example the \code{\link[shiny:helpText]{shiny::helpText()}} el Module to analyze and identify outliers using different methods } \examples{ +# general data example +library(teal.widgets) data <- teal_data() data <- within(data, { - ADSL <- teal.modules.general::rADSL + CO2 <- CO2 + CO2[["primary_key"]] <- seq_len(nrow(CO2)) }) -datanames <- c("ADSL") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- "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 + ) + ) + ), + ggplot2_args = list( + ggplot2_args( + labs = list(subtitle = "Plot generated by Outliers Module") + ) + ) + ) + ) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + +# CDISC data example +library(teal.widgets) + +data <- teal_data() +data <- within(data, { + ADSL <- rADSL +}) +datanames(data) <- "ADSL" +join_keys(data) <- default_cdisc_join_keys[datanames(data)] fact_vars_adsl <- names(Filter(isTRUE, sapply(data[["ADSL"]], is.factor))) vars <- choices_selected(variable_choices(data[["ADSL"]], fact_vars_adsl)) -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_outliers( + modules = modules( + tm_outliers( outlier_var = list( - teal.transform::data_extract_spec( + data_extract_spec( dataname = "ADSL", select = select_spec( label = "Select variable:", @@ -81,9 +134,9 @@ app <- teal::init( ) ), categorical_var = list( - teal.transform::data_extract_spec( + data_extract_spec( dataname = "ADSL", - filter = teal.transform::filter_spec( + filter = filter_spec( vars = vars, choices = value_choices(data[["ADSL"]], vars$selected), selected = value_choices(data[["ADSL"]], vars$selected), @@ -92,7 +145,7 @@ app <- teal::init( ) ), ggplot2_args = list( - teal.widgets::ggplot2_args( + ggplot2_args( labs = list(subtitle = "Plot generated by Outliers Module") ) ) @@ -102,4 +155,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_t_crosstable.Rd b/man/tm_t_crosstable.Rd index d7cf28179..155f6bc90 100644 --- a/man/tm_t_crosstable.Rd +++ b/man/tm_t_crosstable.Rd @@ -53,24 +53,74 @@ For more examples, please see the vignette "Using cross table" via \code{vignette("using-cross-table", package = "teal.modules.general")}. } \examples{ -# Percentage cross table of variables from ADSL dataset +# general data example +library(teal.widgets) data <- teal_data() data <- within(data, { - ADSL <- teal.modules.general::rADSL + mtcars <- mtcars + for (v in c("cyl", "vs", "am", "gear")) { + mtcars[[v]] <- as.factor(mtcars[[v]]) + } + mtcars[["primary_key"]] <- seq_len(nrow(mtcars)) }) -datanames <- c("ADSL") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- "mtcars" +join_keys(data) <- join_keys(join_key("mtcars", "mtcars", "primary_key")) -app <- teal::init( +app <- init( data = data, - modules = teal::modules( - teal.modules.general::tm_t_crosstable( + modules = modules( + tm_t_crosstable( label = "Cross Table", - x = teal.transform::data_extract_spec( + 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 + ) + ), + basic_table_args = basic_table_args( + subtitles = "Table generated by Crosstable Module" + ) + ) + ) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + +# CDISC data example +library(teal.widgets) + +data <- teal_data() +data <- within(data, { + ADSL <- rADSL +}) +datanames(data) <- "ADSL" +join_keys(data) <- default_cdisc_join_keys[datanames(data)] + +app <- init( + data = data, + modules = modules( + tm_t_crosstable( + label = "Cross Table", + x = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- !vapply(data, inherits, logical(1), c("Date", "POSIXct", "POSIXlt")) @@ -82,9 +132,9 @@ app <- teal::init( fixed = FALSE ) ), - y = teal.transform::data_extract_spec( + y = data_extract_spec( dataname = "ADSL", - select = teal.transform::select_spec( + select = select_spec( label = "Select variable:", choices = variable_choices(data[["ADSL"]], subset = function(data) { idx <- vapply(data, is.factor, logical(1)) @@ -95,7 +145,7 @@ app <- teal::init( fixed = FALSE ) ), - basic_table_args = teal.widgets::basic_table_args( + basic_table_args = basic_table_args( subtitles = "Table generated by Crosstable Module" ) ) @@ -104,4 +154,5 @@ app <- teal::init( if (interactive()) { shinyApp(app$ui, app$server) } + } diff --git a/man/tm_variable_browser.Rd b/man/tm_variable_browser.Rd index 5b12bd007..8ed80bb46 100644 --- a/man/tm_variable_browser.Rd +++ b/man/tm_variable_browser.Rd @@ -57,28 +57,50 @@ or numbers with a checkbox allowing users to switch how they are treated (if < 6 then the default is categorical, otherwise it is numeric). } \examples{ +library(teal.widgets) +# module specification used in apps below +tm_variable_browser_module <- tm_variable_browser( + label = "Variable browser", + ggplot2_args = ggplot2_args( + labs = list(subtitle = "Plot generated by Variable Browser Module") + ) +) + +# general data example data <- teal_data() data <- within(data, { - ADSL <- teal.modules.general::rADSL - ADTTE <- teal.modules.general::rADTTE + iris <- iris + mtcars <- mtcars + women <- women + faithful <- faithful + CO2 <- CO2 }) -datanames <- c("ADSL", "ADTTE") -datanames(data) <- datanames -join_keys(data) <- default_cdisc_join_keys[datanames] +datanames(data) <- c("iris", "mtcars", "women", "faithful", "CO2") -app <- teal::init( +app <- init( data = data, - modules( - teal.modules.general::tm_variable_browser( - label = "Variable browser", - ggplot2_args = teal.widgets::ggplot2_args( - labs = list(subtitle = "Plot generated by Variable Browser Module") - ), - ) - ) + modules = modules(tm_variable_browser_module) ) if (interactive()) { shinyApp(app$ui, app$server) } + +# CDISC example data +data <- teal_data() +data <- within(data, { + ADSL <- rADSL + ADTTE <- rADTTE +}) +datanames(data) <- c("ADSL", "ADTTE") +join_keys(data) <- default_cdisc_join_keys[datanames(data)] + +app <- init( + data = data, + modules = modules(tm_variable_browser_module) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + }