diff --git a/R/teal_transform_module.R b/R/teal_transform_module.R index 88652557c7..206b2f9cbf 100644 --- a/R/teal_transform_module.R +++ b/R/teal_transform_module.R @@ -61,7 +61,7 @@ #' #' #' @examples -#' my_transforms <- list( +#' data_transformers <- list( #' teal_transform_module( #' label = "Static transform for iris", #' datanames = "iris", @@ -81,17 +81,17 @@ #' ui = function(id) { #' ns <- NS(id) #' tags$div( -#' numericInput(ns("n_rows"), "Subset n rows", value = 6, min = 1, max = 150, step = 1) +#' numericInput(ns("n_cols"), "Show n columns", value = 5, min = 1, max = 5, step = 1) #' ) #' }, #' server = function(id, data) { #' moduleServer(id, function(input, output, session) { #' reactive({ #' within(data(), -#' { -#' iris <- head(iris, num_rows) -#' }, -#' num_rows = input$n_rows +#' { +#' iris <- iris[, 1:n_cols] +#' }, +#' n_cols = input$n_cols #' ) #' }) #' }) @@ -99,6 +99,14 @@ #' ) #' ) #' +#' app <- init( +#' data = teal_data(iris = iris), +#' modules = example_module(transforms = data_transformers) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } +#' #' @name teal_transform_module #' #' @export @@ -138,7 +146,7 @@ teal_transform_module <- function(ui = NULL, #' @return `function(id, data)` returning `shiny` module #' @examples #' -#' teal_transform_module( +#' trim_iris <- teal_transform_module( #' label = "Simplified interactive transform for iris", #' datanames = "iris", #' ui = function(id) { @@ -148,6 +156,14 @@ teal_transform_module <- function(ui = NULL, #' server = make_teal_transform_server(expression(iris <- head(iris, n_rows))) #' ) #' +#' app <- init( +#' data = teal_data(iris = iris), +#' modules = example_module(transforms = trim_iris) +#' ) +#' if (interactive()) { +#' shinyApp(app$ui, app$server) +#' } +#' #' @export make_teal_transform_server <- function(expr) { function(id, data) { diff --git a/man/make_teal_transform_server.Rd b/man/make_teal_transform_server.Rd index 10b5cf9643..b6bc2e9e79 100644 --- a/man/make_teal_transform_server.Rd +++ b/man/make_teal_transform_server.Rd @@ -24,7 +24,7 @@ with the value of the respective input (matched by the name) - for example in } \examples{ -teal_transform_module( +trim_iris <- teal_transform_module( label = "Simplified interactive transform for iris", datanames = "iris", ui = function(id) { @@ -34,4 +34,12 @@ teal_transform_module( server = make_teal_transform_server(expression(iris <- head(iris, n_rows))) ) +app <- init( + data = teal_data(iris = iris), + modules = example_module(transforms = trim_iris) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + } diff --git a/man/teal_transform_module.Rd b/man/teal_transform_module.Rd index 904fa2db65..95223386e8 100644 --- a/man/teal_transform_module.Rd +++ b/man/teal_transform_module.Rd @@ -76,7 +76,7 @@ the respective input matched by its name. } \examples{ -my_transforms <- list( +data_transformers <- list( teal_transform_module( label = "Static transform for iris", datanames = "iris", @@ -96,17 +96,17 @@ my_transforms <- list( ui = function(id) { ns <- NS(id) tags$div( - numericInput(ns("n_rows"), "Subset n rows", value = 6, min = 1, max = 150, step = 1) + numericInput(ns("n_cols"), "Show n columns", value = 5, min = 1, max = 5, step = 1) ) }, server = function(id, data) { moduleServer(id, function(input, output, session) { reactive({ within(data(), - { - iris <- head(iris, num_rows) - }, - num_rows = input$n_rows + { + iris <- iris[, 1:n_cols] + }, + n_cols = input$n_cols ) }) }) @@ -114,4 +114,12 @@ my_transforms <- list( ) ) +app <- init( + data = teal_data(iris = iris), + modules = example_module(transforms = data_transformers) +) +if (interactive()) { + shinyApp(app$ui, app$server) +} + }