Skip to content

Commit

Permalink
add init part to examples of teal_transform_data so it's clear where …
Browse files Browse the repository at this point in the history
…to pass transformers inside modules
  • Loading branch information
m7pr committed Nov 11, 2024
1 parent 02de519 commit b09ff42
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
30 changes: 23 additions & 7 deletions R/teal_transform_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#'
#'
#' @examples
#' my_transforms <- list(
#' data_transformers <- list(
#' teal_transform_module(
#' label = "Static transform for iris",
#' datanames = "iris",
Expand All @@ -81,24 +81,32 @@
#' 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
#' )
#' })
#' })
#' }
#' )
#' )
#'
#' 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
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion man/make_teal_transform_server.Rd

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

20 changes: 14 additions & 6 deletions man/teal_transform_module.Rd

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

0 comments on commit b09ff42

Please sign in to comment.