Skip to content

Commit

Permalink
Add landing popup argument in init and soft deprecate calling it as…
Browse files Browse the repository at this point in the history
… a normal module (#1284)

Changes:

1. Soft deprecates calling the `landing_popup_module` inside `modules`
argument of `init`
2. Add a new `landing_popup` argument to `init` to accept this module.
3. Update the `TealAppDriver` to accept this new argument.

---------

Signed-off-by: Vedha Viyash <49812166+vedhav@users.noreply.github.com>
Co-authored-by: Dawid Kałędkowski <6959016+gogonzo@users.noreply.github.com>
Co-authored-by: go_gonzo <dawid.kaledkowski@gmail.com>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent da091b6 commit ab8ac73
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 64 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# teal 0.15.2.9047

### Breaking changes
* The `landing_popup_module()` needs to be passed as the `landing_popup` argument of `init` instead of being passed as a module of the `modules` argument of `init`

### Enhancement
* Provided progress bar for modules loading and data filtering during teal app startup.

Expand Down
6 changes: 4 additions & 2 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' @description
#' Initialize a `TealAppDriver` object for testing a `teal` application.
#'
#' @param data,modules,filter,title,header,footer arguments passed to `init`
#' @param data,modules,filter,title,header,footer,landing_popup arguments passed to `init`
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
#' timeout_ parameter in the `TealAppDriver` class.
#' Defaults to 20s.
Expand All @@ -37,6 +37,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
title = build_app_title(),
header = tags$p(),
footer = tags$p(),
landing_popup = NULL,
timeout = rlang::missing_arg(),
load_timeout = rlang::missing_arg(),
...) {
Expand All @@ -49,7 +50,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
filter = filter,
title = title,
header = header,
footer = footer
footer = footer,
landing_popup = landing_popup,
)

# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
Expand Down
22 changes: 14 additions & 8 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#' @param id (`character`) optional
#' string specifying the `shiny` module id in cases it is used as a `shiny` module
#' rather than a standalone `shiny` app. This is a legacy feature.
#' @param landing_popup (`teal_module`) optional
#' A `landing_popup_module` to show up as soon as the teal app is initialized.
#'
#' @return Named list containing server and UI functions.
#'
Expand Down Expand Up @@ -99,7 +101,8 @@ init <- function(data,
title = build_app_title(),
header = tags$p(),
footer = tags$p(),
id = character(0)) {
id = character(0),
landing_popup = NULL) {
logger::log_debug("init initializing teal app with: data ('{ class(data) }').")

# argument checking (independent)
Expand All @@ -115,6 +118,7 @@ init <- function(data,
)
}
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module"))
checkmate::assert_class(landing_popup, "teal_module_landing", null.ok = TRUE)

## `modules`
checkmate::assert(
Expand Down Expand Up @@ -159,10 +163,15 @@ init <- function(data,
# argument transformations
## `modules` - landing module
landing <- extract_module(modules, "teal_module_landing")
landing_module <- NULL
if (length(landing) == 1L) {
landing_module <- landing[[1L]]
landing_popup <- landing[[1L]]
modules <- drop_module(modules, "teal_module_landing")
# TODO: verify the version before release.
lifecycle::deprecate_soft(
when = "0.16",
what = "landing_popup_module()",
details = "Pass `landing_popup_module` to the `landing_popup` argument of the `init` instead of wrapping it into `modules()` and passing to the `modules` argument"

Check warning on line 173 in R/init.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/init.R,line=173,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 169 characters.
)
} else if (length(landing) > 1L) {
stop("Only one `landing_popup_module` can be used.")
}
Expand Down Expand Up @@ -242,11 +251,8 @@ init <- function(data,
)
},
server = function(input, output, session) {
# todo: remove landing page from here to srv_teal
# - fix srv_data first to not use modal (can't display two in the same time)
# https://github.com/insightsengineering/teal/issues/1244
if (!is.null(landing_module)) {
do.call(landing_module$server, c(list(id = "landing_module_shiny_id"), landing_module$server_args))
if (!is.null(landing_popup)) {
do.call(landing_popup$server, c(list(id = "landing_module_shiny_id"), landing_popup$server_args))
}
srv_teal(id = ns("teal"), data = data, modules = modules, filter = deep_copy_filter(filter))
}
Expand Down
36 changes: 18 additions & 18 deletions R/landing_popup_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#' app1 <- init(
#' data = teal_data(iris = iris),
#' modules = modules(
#' landing_popup_module(
#' content = "A place for the welcome message or a disclaimer statement.",
#' buttons = modalButton("Proceed")
#' ),
#' example_module()
#' ),
#' landing_popup = landing_popup_module(
#' content = "A place for the welcome message or a disclaimer statement.",
#' buttons = modalButton("Proceed")
#' )
#' )
#' if (interactive()) {
Expand All @@ -31,21 +31,21 @@
#' app2 <- init(
#' data = teal_data(iris = iris),
#' modules = modules(
#' landing_popup_module(
#' title = "Welcome",
#' content = tags$b(
#' "A place for the welcome message or a disclaimer statement.",
#' style = "color: red;"
#' ),
#' buttons = tagList(
#' modalButton("Proceed"),
#' actionButton("read", "Read more",
#' onclick = "window.open('http://google.com', '_blank')"
#' ),
#' actionButton("close", "Reject", onclick = "window.close()")
#' )
#' ),
#' example_module()
#' ),
#' landing_popup = landing_popup_module(
#' title = "Welcome",
#' content = tags$b(
#' "A place for the welcome message or a disclaimer statement.",
#' style = "color: red;"
#' ),
#' buttons = tagList(
#' modalButton("Proceed"),
#' actionButton("read", "Read more",
#' onclick = "window.open('http://google.com', '_blank')"
#' ),
#' actionButton("close", "Reject", onclick = "window.close()")
#' )
#' )
#' )
#'
Expand Down
4 changes: 4 additions & 0 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#' Module to create a `teal` app. This module (`ui` and `server`) is called directly by [init()] after
#' initial argument checking and setting default values. This module can be called directly and
#' included in your custom application.
#'
#' Please note that [init()] adds `reporter_previewer_module` automatically, which is not a case
#' when calling `ui/srv_teal` directly.
#'
#' 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
#' component in the app. Reactive change of the `data` triggers reload of the app and possibly
Expand Down
3 changes: 2 additions & 1 deletion man/TealAppDriver.Rd

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

6 changes: 5 additions & 1 deletion man/init.Rd

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

36 changes: 18 additions & 18 deletions man/landing_popup_module.Rd

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

5 changes: 5 additions & 0 deletions man/module_teal.Rd

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

32 changes: 16 additions & 16 deletions tests/testthat/test-shinytest2-landing_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ testthat::test_that("e2e: teal app with landing_popup_module initializes with no
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
title = "Welcome",
content = tags$b("A welcome message!", style = "color: red;")
),
example_module()
),
landing_popup = landing_popup_module(
title = "Welcome",
content = tags$b("A welcome message!", style = "color: red;")
)
)

Expand All @@ -23,9 +23,9 @@ testthat::test_that("e2e: app with default landing_popup_module creates modal co
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(),
example_module()
)
),
landing_popup = landing_popup_module()
)

testthat::expect_equal(
Expand All @@ -41,9 +41,9 @@ testthat::test_that("e2e: when default landing_popup_module is closed, it shows
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(),
example_module()
)
),
landing_popup = landing_popup_module()
)

# Button is clicked.
Expand Down Expand Up @@ -91,12 +91,12 @@ testthat::test_that(
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
title = modal_title,
content = modal_content,
buttons = modal_buttons
),
example_module()
),
landing_popup = landing_popup_module(
title = modal_title,
content = modal_content,
buttons = modal_buttons
)
)

Expand Down Expand Up @@ -145,10 +145,10 @@ testthat::test_that("e2e: when customized button in landing_popup_module is clic
app <- TealAppDriver$new(
data = simple_teal_data(),
modules = modules(
landing_popup_module(
buttons = actionButton("read", "Read more", onclick = onclick_text)
),
example_module()
),
landing_popup = landing_popup_module(
buttons = actionButton("read", "Read more", onclick = onclick_text)
)
)

Expand Down

0 comments on commit ab8ac73

Please sign in to comment.