diff --git a/R/module_session_info.R b/R/module_session_info.R index 2066ce687..169120494 100644 --- a/R/module_session_info.R +++ b/R/module_session_info.R @@ -1,6 +1,8 @@ #' `teal` user session info module #' -#' Module to display the user session info popup and to download a lockfile. +#' Module to display the user session info popup and to download a lockfile. Module is included +#' when running [init()] but skipped when using [`module_teal`]. Please be aware that session info +#' contains R session information, so multiple module's calls will share the same information. #' #' @rdname module_session_info #' @name module_session_info diff --git a/R/module_teal.R b/R/module_teal.R index bbf6d7cc3..8696a59c8 100644 --- a/R/module_teal.R +++ b/R/module_teal.R @@ -6,8 +6,7 @@ #' #' @details #' This module can be used instead of [init()] in custom Shiny applications. Unlike [init()], it doesn't -#' automatically include `reporter_previewer_module`, `module_session_info`, or UI components like -#' `header`, `footer`, and `title` which can be added separately in the Shiny app consuming this module. +#' automatically include [`module_session_info`]. #' #' Module is responsible for creating the main `shiny` app layout and initializing all the necessary #' components. This module establishes reactive connection between the input `data` and every other diff --git a/_pkgdown.yml b/_pkgdown.yml index c8c4b21e4..fe7e8148d 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -56,17 +56,12 @@ articles: navbar: Get started contents: - getting-started-with-teal - - title: Using `teal` - navbar: Using `teal` - contents: - - filter-panel - - teal-options - - bootstrap-themes-in-teal - title: Data in `teal` apps navbar: Data in `teal` apps contents: - including-data-in-teal-applications - data-as-shiny-module + - filter-panel - data-transform-as-shiny-module - title: Extending `teal` navbar: Extending `teal` @@ -74,6 +69,12 @@ articles: - creating-custom-modules - adding-support-for-reporting - customizing-module-output + - title: Using `teal` + navbar: Using `teal` + contents: + - teal-as-a-module + - teal-options + - bootstrap-themes-in-teal - title: 📃 Technical blueprint desc: > The purpose of the blueprint is to aid new developer’s comprehension of the diff --git a/man/module_session_info.Rd b/man/module_session_info.Rd index 4fb5b918f..b373b3611 100644 --- a/man/module_session_info.Rd +++ b/man/module_session_info.Rd @@ -17,7 +17,9 @@ srv_session_info(id) \code{NULL} invisibly } \description{ -Module to display the user session info popup and to download a lockfile. +Module to display the user session info popup and to download a lockfile. Module is included +when running \code{\link[=init]{init()}} but skipped when using \code{\link{module_teal}}. Please be aware that session info +contains R session information, so multiple module's calls will share the same information. } \examples{ ui <- fluidPage( diff --git a/man/module_teal.Rd b/man/module_teal.Rd index c6ba7b206..df3329ed7 100644 --- a/man/module_teal.Rd +++ b/man/module_teal.Rd @@ -33,8 +33,7 @@ Module to create a \code{teal} app as a Shiny Module. } \details{ This module can be used instead of \code{\link[=init]{init()}} in custom Shiny applications. Unlike \code{\link[=init]{init()}}, it doesn't -automatically include \code{reporter_previewer_module}, \code{module_session_info}, or UI components like -\code{header}, \code{footer}, and \code{title} which can be added separately in the Shiny app consuming this module. +automatically include \code{\link{module_session_info}}. Module is responsible for creating the main \code{shiny} app layout and initializing all the necessary components. This module establishes reactive connection between the input \code{data} and every other diff --git a/vignettes/getting-started-with-teal.Rmd b/vignettes/getting-started-with-teal.Rmd index b443a6e49..c2edcbb8d 100644 --- a/vignettes/getting-started-with-teal.Rmd +++ b/vignettes/getting-started-with-teal.Rmd @@ -107,7 +107,7 @@ To use our predefined modules, see the references below for links to these modul ### Defining filters The optional `filter` argument in `init` allows you to initialize the application with predefined filters. -For further details see [Filter Panel vignette](filter-panel.html) . +For further details see [Filter Panel vignette](filter-panel.html). ### Reporting @@ -122,6 +122,10 @@ Note that `teal` does not display the code, that is the modules' responsibility. For example, the `example_module` function used above shows the code in the main panel together with other outputs. For more details see [this vignette](including-data-in-teal-applications.html). +### Embedding teal in shiny application + +Advanced shiny users can include teal application in their Shiny application. For further details see [teal as a module](teal-as-a-module.html). + ## Where to go next To learn more about the `teal` framework we recommend first exploring some of the available analysis modules. diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd new file mode 100644 index 000000000..c28a57b30 --- /dev/null +++ b/vignettes/teal-as-a-module.Rmd @@ -0,0 +1,70 @@ +--- +title: "Teal as a Module" +author: "NEST CoreDev" +output: + rmarkdown::html_vignette: + toc: true +vignette: > + %\VignetteIndexEntry{Teal as a Module} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +# Introduction + +A Shiny developer 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()`. +Using Teal as modules offers several advantages such as: + +- Including one or multiple Teal applications in other app. +- Run Teal applications based on the dynamically created components like initial data, modules, filters. + +# Example + +Example below demonstrates how to embed Teal as a module in a Shiny application. +Here, user can select dataset names which will be handed over and displayed in the Teal module. On the server side `srv_teal()` is called using the reactive `teal_data` object passed from the server of the parent app. + +```{r setup, include=FALSE} +library(teal) +``` +```{r app} +library(teal) + +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) +} +``` + +```{r shinylive_iframe, echo = FALSE, out.width = '150%', out.extra = 'style = "position: relative; z-index:1"', eval = requireNamespace("roxy.shinylive", quietly = TRUE) && knitr::is_html_output() && identical(Sys.getenv("IN_PKGDOWN"), "true")} +code <- paste0(c( + "interactive <- function() TRUE", + knitr::knit_code$get("app") +), collapse = "\n") + +url <- roxy.shinylive::create_shinylive_url(code) +knitr::include_url(url, height = "800px") +```