Skip to content

Commit

Permalink
Merge e4e490f into caf2d6f
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo authored Feb 4, 2025
2 parents caf2d6f + e4e490f commit 4455c05
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 13 deletions.
4 changes: 3 additions & 1 deletion R/module_session_info.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,25 @@ 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`
contents:
- 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
Expand Down
4 changes: 3 additions & 1 deletion man/module_session_info.Rd

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

3 changes: 1 addition & 2 deletions man/module_teal.Rd

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

6 changes: 5 additions & 1 deletion vignettes/getting-started-with-teal.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
70 changes: 70 additions & 0 deletions vignettes/teal-as-a-module.Rmd
Original file line number Diff line number Diff line change
@@ -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")
```

0 comments on commit 4455c05

Please sign in to comment.