-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
gogonzo
wants to merge
4
commits into
main
Choose a base branch
from
1450_vignette
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−13
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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) | ||
} | ||
``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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()
? )There was a problem hiding this comment.
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?No it wouldn't. But what do you think I should add?
data
,modules
andfilter
arguments are well documented inmodule_teal
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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