Skip to content

Commit

Permalink
chore: add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Nov 6, 2024
1 parent c02d16f commit 74512e4
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 1 deletion.
109 changes: 108 additions & 1 deletion R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,17 @@ modules <- function(..., label = "root") {
#' format.teal_modules(). Determines whether to show "TEAL ROOT" header
#' @param what (`character`) Specifes which metadata to display.
#' Possible values: "datasets", "properties", "ui_args", "server_args", "transformers"
#' @examples
#' mod <- module(
#' label = "My Custom Module",
#' server = function(id, data, ...) {},
#' ui = function(id, ...) {},
#' datanames = c("ADSL", "ADTTE"),
#' transformers = list(),
#' ui_args = list(a = 1, b = "b"),
#' server_args = list(x = 5, y = list(p = 1))
#' )
#' cat(format(mod))
#' @export
format.teal_module <- function(
x, indent = 0, is_last = FALSE, parent_prefix = "",
Expand Down Expand Up @@ -394,11 +405,107 @@ format.teal_module <- function(
}

#' @rdname teal_modules
#' @examples
#' custom_module <- function(label = "label", ui_args = NULL, server_args = NULL, datanames = "all", transformers = list(), bk = FALSE) { # nolint line_length
#' ans <- module(
#' label,
#' server = function(id, data, ...) {},
#' ui = function(id, ...) {
#' },
#' datanames = datanames,
#' transformers = transformers,
#' ui_args = ui_args,
#' server_args = server_args
#' )
#' attr(ans, "teal_bookmarkable") <- bk
#' ans
#' }
#'
#' dummy_transformer <- teal_transform_module(
#' label = "Dummy Transform",
#' ui = function(id) div("(does nothing)"),
#' server = function(id, data) {
#' moduleServer(id, function(input, output, session) data)
#' }
#' )
#'
#' plot_transformer <- teal_transform_module(
#' label = "Plot Settings",
#' ui = function(id) div("(does nothing)"),
#' server = function(id, data) {
#' moduleServer(id, function(input, output, session) data)
#' }
#' )
#'
#' complete_modules <- modules(
#' custom_module(
#' label = "Data Overview",
#' datanames = c("ADSL", "ADAE", "ADVS"),
#' ui_args = list(
#' view_type = "table",
#' page_size = 10,
#' filters = c("ARM", "SEX", "RACE")
#' ),
#' server_args = list(
#' cache = TRUE,
#' debounce = 1000
#' ),
#' transformers = list(dummy_transformer),
#' bk = TRUE
#' ),
#' modules(
#' label = "Nested 1",
#' custom_module(
#' label = "Interactive Plots",
#' datanames = c("ADSL", "ADVS"),
#' ui_args = list(
#' plot_type = c("scatter", "box", "line"),
#' height = 600,
#' width = 800,
#' color_scheme = "viridis"
#' ),
#' server_args = list(
#' render_type = "svg",
#' cache_plots = TRUE
#' ),
#' transformers = list(dummy_transformer, plot_transformer),
#' bk = TRUE
#' ),
#' modules(
#' label = "Nested 2",
#' custom_module(
#' label = "Summary Statistics",
#' datanames = "ADSL",
#' ui_args = list(
#' stats = c("mean", "median", "sd", "range"),
#' grouping = c("ARM", "SEX")
#' )
#' ),
#' modules(
#' label = "Labeled nested modules",
#' custom_module(
#' label = "Subgroup Analysis",
#' datanames = c("ADSL", "ADAE"),
#' ui_args = list(
#' subgroups = c("AGE", "SEX", "RACE"),
#' analysis_type = "stratified"
#' ),
#' bk = TRUE
#' )
#' ),
#' modules(custom_module(label = "Subgroup Analysis in non-labled modules"))
#' )
#' ),
#' custom_module("Non-nested module")
#' )
#'
#' cat(format(complete_modules))
#' cat(format(complete_modules, what = c("ui_args", "server_args", "transformers")))
#' @export
format.teal_modules <- function(x, indent = 0, is_root = TRUE, is_last = FALSE, parent_prefix = "", ...) {
if (is_root) {
header <- pasten(crayon::bold("TEAL ROOT"))
new_parent_prefix <- " " # Initial indent for root level
new_parent_prefix <- " " #' Initial indent for root level
} else {
if (!is.null(x$label)) {
branch <- if (is_last) "└─" else "├─"
Expand Down
105 changes: 105 additions & 0 deletions man/teal_modules.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 74512e4

Please sign in to comment.