From b2025b06d518d66fa90827218b9e8000812d4aa2 Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Wed, 29 Jan 2025 11:27:31 +0100 Subject: [PATCH 1/7] vignette and tiny docs reorg --- R/module_session_info.R | 4 +- R/module_teal.R | 3 +- _pkgdown.yml | 13 +++--- man/module_session_info.Rd | 4 +- man/module_teal.Rd | 3 +- vignettes/getting-started-with-teal.Rmd | 6 ++- vignettes/teal-as-a-module.Rmd | 57 +++++++++++++++++++++++++ 7 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 vignettes/teal-as-a-module.Rmd diff --git a/R/module_session_info.R b/R/module_session_info.R index 682283ada..8568b59a8 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 the module called multiple times 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 d78e7eb94..dc14c1927 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 `reporter_previewer_module`, `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 1eea00f5f..9be034012 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 - 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 diff --git a/man/module_session_info.Rd b/man/module_session_info.Rd index 1c15bd28b..b977104c4 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 the module called multiple times will share the same information. } \examples{ ui <- fluidPage( diff --git a/man/module_teal.Rd b/man/module_teal.Rd index c6ba7b206..1f398d9b5 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{reporter_previewer_module}, \code{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 921505cf9..4de8a363d 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 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..8d1d25c7d --- /dev/null +++ b/vignettes/teal-as-a-module.Rmd @@ -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 + +Shiny developer who is 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()`. +Team as module 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 shows how to use the Teal module in Shiny app. In the example `srv_teal()` is called with the dynamic +data created in the server of the parent app. + +```{r setup} +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) +} +``` From ed773ae72774e1fc3e46075e162fd4266f322b7e Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Wed, 29 Jan 2025 14:41:04 +0100 Subject: [PATCH 2/7] module_teal includes reporter_previewer_module automatically --- R/module_teal.R | 2 +- man/module_teal.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/module_teal.R b/R/module_teal.R index 219f831c3..8696a59c8 100644 --- a/R/module_teal.R +++ b/R/module_teal.R @@ -6,7 +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`. +#' 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/man/module_teal.Rd b/man/module_teal.Rd index 1f398d9b5..df3329ed7 100644 --- a/man/module_teal.Rd +++ b/man/module_teal.Rd @@ -33,7 +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}. +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 From 58bd91d7d7c3c73753c7b8f600d0e47f3513af04 Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Thu, 30 Jan 2025 09:09:14 +0100 Subject: [PATCH 3/7] review comments --- R/module_session_info.R | 2 +- man/module_session_info.Rd | 2 +- vignettes/getting-started-with-teal.Rmd | 2 +- vignettes/teal-as-a-module.Rmd | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/R/module_session_info.R b/R/module_session_info.R index 8568b59a8..5059b5db6 100644 --- a/R/module_session_info.R +++ b/R/module_session_info.R @@ -2,7 +2,7 @@ #' #' 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 the module called multiple times will share the same information. +#' 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/man/module_session_info.Rd b/man/module_session_info.Rd index b977104c4..ed6801020 100644 --- a/man/module_session_info.Rd +++ b/man/module_session_info.Rd @@ -19,7 +19,7 @@ srv_session_info(id) \description{ 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 the module called multiple times will share the same information. +contains R session information, so multiple module's calls will share the same information. } \examples{ ui <- fluidPage( diff --git a/vignettes/getting-started-with-teal.Rmd b/vignettes/getting-started-with-teal.Rmd index 4de8a363d..6ca4c05a7 100644 --- a/vignettes/getting-started-with-teal.Rmd +++ b/vignettes/getting-started-with-teal.Rmd @@ -124,7 +124,7 @@ 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 application. For further details see [teal as a module](teal-as-a-module.html) +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 diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd index 8d1d25c7d..bec71baf5 100644 --- a/vignettes/teal-as-a-module.Rmd +++ b/vignettes/teal-as-a-module.Rmd @@ -12,19 +12,19 @@ vignette: > # Introduction -Shiny developer who is 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()`. -Team as module offers several advantages such as: +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 shows how to use the Teal module in Shiny app. In the example `srv_teal()` is called with the dynamic -data created in the server of the parent app. +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} +```{r setup, message=FALSE} library(teal) data <- teal_data() |> within({ From b1f5cf2dbb225aa2b81e0ccbb822fc0024cf3174 Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Fri, 31 Jan 2025 09:10:37 +0100 Subject: [PATCH 4/7] @llrs-roche comment --- vignettes/teal-as-a-module.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd index bec71baf5..e70025a07 100644 --- a/vignettes/teal-as-a-module.Rmd +++ b/vignettes/teal-as-a-module.Rmd @@ -22,7 +22,7 @@ Using Teal as modules offers several advantages such as: # 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. +Here, `srv_teal()` is called using the reactive `teal_data` object passed from the server of the parent app. ```{r setup, message=FALSE} library(teal) From 7a38e3f978636038c65641369809907129d81a72 Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Tue, 4 Feb 2025 08:42:32 +0100 Subject: [PATCH 5/7] teal, `teal` -> Teal --- vignettes/teal-as-a-module.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd index e70025a07..e68c5f493 100644 --- a/vignettes/teal-as-a-module.Rmd +++ b/vignettes/teal-as-a-module.Rmd @@ -1,11 +1,11 @@ --- -title: "teal as a module" +title: "Teal as a Module" author: "NEST CoreDev" output: rmarkdown::html_vignette: toc: true vignette: > - %\VignetteIndexEntry{teal as a module} + %\VignetteIndexEntry{Teal as a Module} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -16,12 +16,12 @@ A Shiny developer interested in embedding Teal application into its own app, can 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. +- 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. +Example below demonstrates how to embed Teal as a module in a Shiny application. Here, `srv_teal()` is called using the reactive `teal_data` object passed from the server of the parent app. ```{r setup, message=FALSE} From a529c5bc8da681b30991de734a59e41ddb7bd65e Mon Sep 17 00:00:00 2001 From: Dawid Kaledkowski Date: Tue, 4 Feb 2025 09:43:07 +0100 Subject: [PATCH 6/7] @llrs-roche suggestion --- vignettes/teal-as-a-module.Rmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd index e68c5f493..26cad67f7 100644 --- a/vignettes/teal-as-a-module.Rmd +++ b/vignettes/teal-as-a-module.Rmd @@ -22,7 +22,7 @@ Using Teal as modules offers several advantages such as: # Example Example below demonstrates how to embed Teal as a module in a Shiny application. -Here, `srv_teal()` is called using the reactive `teal_data` object passed from the server of the parent app. +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, message=FALSE} library(teal) @@ -55,3 +55,4 @@ if (interactive()) { shinyApp(ui_app, srv_app) } ``` + From 6332f91eb153c887e1941f72bbb547f786f591ff Mon Sep 17 00:00:00 2001 From: vedhav Date: Tue, 4 Feb 2025 14:15:36 +0530 Subject: [PATCH 7/7] docs: add shinylive to the vignette --- vignettes/teal-as-a-module.Rmd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vignettes/teal-as-a-module.Rmd b/vignettes/teal-as-a-module.Rmd index 26cad67f7..c28a57b30 100644 --- a/vignettes/teal-as-a-module.Rmd +++ b/vignettes/teal-as-a-module.Rmd @@ -24,7 +24,10 @@ Using Teal as modules offers several advantages such as: 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, message=FALSE} +```{r setup, include=FALSE} +library(teal) +``` +```{r app} library(teal) data <- teal_data() |> within({ @@ -56,3 +59,12 @@ if (interactive()) { } ``` +```{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") +```