Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vignette: shiny as a module #1467

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
- decorate-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
57 changes: 57 additions & 0 deletions vignettes/teal-as-a-module.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
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 application 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, `srv_teal()` is called using the dynamic data generated within the server of the parent app.

```{r setup, message=FALSE}
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)
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a final comment on the example would be good. Like describing the differences with a pure teal app from the final end user (or for the app developer: would it work without teal_data() ? )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describing the differences with a pure teal app from the final end user

What do you mean? Isn't "Unlike init(), this module will not automatically include session info footer" enough?

would it work without teal_data()

No it wouldn't. But what do you think I should add? data, modules and filter arguments are well documented in module_teal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Isn't "Unlike init(), this module will not automatically include session info footer" enough?

For example, when I created this app, the left panel was not there, this is evident for us but it might not be so for new users or app developers that might not know how it works. I usually struggle with vignettes that don't lower the level and assume the user already knows the package.

would it work without teal_data()

No it wouldn't. But what do you think I should add? data, modules and filter arguments are well documented in module_teal.

The idea behind vignettes in my opinion are to serve as introduction to the user. If this is documented on module_teal we can mention this to redirect the users to the detailed documentation of the function or to other vignettes.

My personal preference is to provide extra guidance than assume the user already knows something and not following through the vignette. But it is hard to set the level required for a vignette. Please feel free to resolve this conversation

Loading