-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
``` |