Skip to contents

[Experimental]

Create a teal_data_module object for custom transformation of data for pre-processing before passing the data into the module.

Usage

teal_transform_module(
  ui = function(id) NULL,
  server = function(id, data) data,
  label = "transform module",
  datanames = character(0)
)

Arguments

ui

(function(id)) shiny module UI function; must only take id argument

server

(function(id, data)) shiny module server function; that takes id and data argument, where the id is the module id and data is the reactive teal_data input. The server function must return reactive expression containing teal_data object.

The server function definition should not use eventReactive as it may lead to unexpected behavior. See vignettes("data-transform-as-shiny-module") for more information.

label

(character(1)) Label of the module.

datanames

(character) Names of the datasets that are relevant for this module to evaluate. If set to character(0) then module would receive modules() datanames.

Details

teal_transform_module creates a teal_data_module object to transform data in a teal application. This transformation happens after the data has passed through the filtering activity in teal. The transformed data is then sent to the server of the teal_module().

See vignette vignette("data-transform-as-shiny-module", package = "teal") for more details.

Examples

my_transformers <- list(
  teal_transform_module(
    label = "Custom transform for iris",
    datanames = "iris",
    ui = function(id) {
      ns <- NS(id)
      tags$div(
        numericInput(ns("n_rows"), "Subset n rows", value = 6, min = 1, max = 150, 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
          )
        })
      })
    }
  )
)