Shiny developer who is interested in embedding Teal application into
its own app, can use the Teal module composed of ui_teal()
and srv_teal()
functions. Unlike init()
, this
module will not automatically include session info footer, but it is
possible to add it manually with ui_session_info()
and
srv_session_info()
. Team as module offers several
advantages such as:
Example below shows how to use the Teal module in Shiny app. In the
example srv_teal()
is called with the dynamic data created
in the server of the parent app.
## Loading required package: shiny
## Loading required package: teal.data
## Loading required package: teal.code
## Loading required package: teal.slice
## Registered S3 method overwritten by 'teal':
## method from
## c.teal_slices teal.slice
##
## You are using teal version 0.15.2.9115
##
## Attaching package: 'teal'
## The following objects are masked from 'package:teal.slice':
##
## as.teal_slices, teal_slices
data <- teal_data() |> within({
iris <- iris
mtcars <- mtcars
df <- data.frame(a = 1:10, b = letters[1:10])
})
mods <- modules(
example_module("mod1"),
example_module("mod2")
)
ui_app <- fluidPage(
title = "Your app with teal as a module",
selectInput("datasets", "Select datasets", choices = c("iris", "mtcars", "df"), selected = "iris", multiple = TRUE),
ui_teal("teal", mods),
ui_session_info("session_info")
)
srv_app <- function(input, output, session) {
data_subset <- reactive(data[input$datasets])
srv_teal("teal", data = data_subset, modules = mods)
srv_session_info("session_info")
}
if (interactive()) {
shinyApp(ui_app, srv_app)
}