Skip to contents

[Stable]

Create a nested tab structure to embed modules in a teal application.

Usage

module(
  label = "module",
  server = function(id, ...) {
     moduleServer(id, function(input, output, session) {
 
       })
 },
  ui = function(id, ...) {
     tags$p(paste0("This module has no UI (id: ", id, " )"))

    },
  filters,
  datanames = "all",
  server_args = NULL,
  ui_args = NULL
)

modules(..., label = "root")

# S3 method for teal_module
format(x, indent = 0, ...)

# S3 method for teal_module
print(x, ...)

# S3 method for teal_modules
format(x, indent = 0, ...)

# S3 method for teal_modules
print(x, ...)

Arguments

label

(character(1)) Label shown in the navigation item for the module or module group. For modules() defaults to "root". See Details.

server

(function) shiny module with following arguments:

  • id - teal will set proper shiny namespace for this module (see shiny::moduleServer()).

  • input, output, session - (not recommended) then shiny::callModule() will be used to call a module.

  • data (optional) module will receive a teal_data object, a list of reactive (filtered) data specified in the filters argument.

  • datasets (optional) module will receive FilteredData. (See teal.slice::FilteredData).

  • reporter (optional) module will receive Reporter. (See teal.reporter::Reporter).

  • filter_panel_api (optional) module will receive FilterPanelAPI. (See teal.slice::FilterPanelAPI).

  • ... (optional) server_args elements will be passed to the module named argument or to the ....

ui

(function) shiny UI module function with following arguments:

  • id - teal will set proper shiny namespace for this module.

  • ... (optional) ui_args elements will be passed to the module named argument or to the ....

filters

(character) Deprecated. Use datanames instead.

datanames

(character) A vector with datanames that are relevant for the item. The filter panel will automatically update the shown filters to include only filters in the listed datasets. NULL will hide the filter panel, and the keyword "all" will show filters of all datasets. datanames also determines a subset of datasets which are appended to the data argument in server function.

server_args

(named list) with additional arguments passed on to the server function.

ui_args

(named list) with additional arguments passed on to the UI function.

...
  • For modules(): (teal_module or teal_modules) Objects to wrap into a tab.

  • For format() and print(): Arguments passed to other methods.

x

(teal_module or teal_modules) Object to format/print.

indent

(integer(1)) Indention level; each nested element is indented one level more.

Value

module() returns an object of class teal_module.

modules() returns a teal_modules object which contains following fields:

  • label: taken from the label argument.

  • children: a list containing objects passed in .... List elements are named after their label attribute converted to a valid shiny id.

Details

module() creates an instance of a teal_module that can be placed in a teal application. modules() shapes the structure of a the application by organizing teal_module within the navigation panel. It wraps teal_module and teal_modules objects in a teal_modules object, which results in a nested structure corresponding to the nested tabs in the final application.

Note that for modules() label comes after ..., so it must be passed as a named argument, otherwise it will be captured by ....

The labels "global_filters" and "Report previewer" are reserved because they are used by the mapping argument of teal_slices() and the report previewer module reporter_previewer_module(), respectively.

Examples

library(shiny)

module_1 <- module(
  label = "a module",
  server = function(id, data) {
    moduleServer(
      id,
      module = function(input, output, session) {
        output$data <- renderDataTable(data()[["iris"]])
      }
    )
  },
  ui = function(id) {
    ns <- NS(id)
    tagList(dataTableOutput(ns("data")))
  },
  datanames = "all"
)

module_2 <- module(
  label = "another module",
  server = function(id) {
    moduleServer(
      id,
      module = function(input, output, session) {
        output$text <- renderText("Another Module")
      }
    )
  },
  ui = function(id) {
    ns <- NS(id)
    tagList(textOutput(ns("text")))
  },
  datanames = NULL
)

modules <- modules(
  label = "modules",
  modules(
    label = "nested modules",
    module_1
  ),
  module_2
)

app <- init(
  data = teal_data(iris = iris),
  modules = modules
)

if (interactive()) {
  shinyApp(app$ui, app$server)
}