From 259cbfee42bfa997fcbf6ce0bc1771ace0392496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 17 Apr 2024 10:23:28 +0200 Subject: [PATCH 1/2] 712 - `{shinytest2}` Injects `library` of tmg for shiny app (#731) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Pull Request Part of #712 ### Changes description - Changes `shinyApp` function used in `TealAppDriver` to trick `shinytest2` into loading the package - This allows the module server function to call package in `Depends` without prefixing #### How to test? - Checkout branch - Save test below in the `tests/testthat` directory - Restart R session (don't load package afterwards!) - Run `devtools::test(filter = "test-remove_me.R")` or whatever name you use - Run test interactively after loading package ```r # Save in tests/testthat/test-remove_me.R testthat::test_that("sample test", { # general data example data <- teal.data::teal_data() data <- within(data, { require(nestcolor) CO2 <- CO2 }) teal.data::datanames(data) <- "CO2" mod <- teal.modules.general::tm_g_scatterplot( label = "Scatterplot Choices", x = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["CO2"]], c("conc", "uptake")), selected = "conc", multiple = FALSE, fixed = FALSE ) ), y = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["CO2"]], c("conc", "uptake")), selected = "uptake", multiple = FALSE, fixed = FALSE ) ), color_by = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices( data[["CO2"]], c("Plant", "Type", "Treatment", "conc", "uptake") ), selected = NULL, multiple = FALSE, fixed = FALSE ) ), size_by = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["CO2"]], c("conc", "uptake")), selected = "uptake", multiple = FALSE, fixed = FALSE ) ), row_facet = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), col_facet = teal.transform::data_extract_spec( dataname = "CO2", select = teal.transform::select_spec( label = "Select variable:", choices = teal.transform::variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), selected = NULL, multiple = FALSE, fixed = FALSE ) ), ggplot2_args = teal.widgets::ggplot2_args( labs = list(subtitle = "Plot generated by Scatterplot Module") ) ) app_driver <- init_teal_app_driver( data = data, modules = list(mod) ) app_driver$expect_no_validation_error() }) ``` --------- Signed-off-by: André Veríssimo <211358+averissimo@users.noreply.github.com> Co-authored-by: Marcin <133694481+m7pr@users.noreply.github.com> --- tests/testthat/helper-TealAppDriver.R | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index 39e5c28d9..3e9e7cf6b 100644 --- a/tests/testthat/helper-TealAppDriver.R +++ b/tests/testthat/helper-TealAppDriver.R @@ -1,5 +1,28 @@ -# Import non-exported TealAppDriver from `teal` package -TealAppDriver <- getFromNamespace("TealAppDriver", "teal") # nolint: object_name. +# Initialization function to create a new TealAppDriver object +# +# By manipulating the server function as below, we can hint {shinytest2} to load +# this package and its "Depends". +# Related to https://github.com/rstudio/shinytest2/issues/381 +init_teal_app_driver <- function(...) { + testthat::with_mocked_bindings( + { + TealAppDriver <- getFromNamespace("TealAppDriver", "teal") # nolint: object_name. + TealAppDriver$new(...) + }, + shinyApp = function(ui, server, ...) { + functionBody(server) <- bquote({ + # Hint to shinytest2 that this package should be available (via {globals}) + .hint_to_load_package <- add_facet_labels + .(functionBody(server)) + }) + + shiny::shinyApp(ui, server, ...) + }, + # The relevant shinyApp call in `TealAppDriver` is being called without prefix, + # hence why the package bindings that is changed is in {teal} and not {shiny} + .package = "teal" + ) +} # Helper function simple_teal_data <- function() { From a1af9a5c894cc1e6e74880ce6d600b50798c8521 Mon Sep 17 00:00:00 2001 From: averissimo Date: Wed, 17 Apr 2024 08:24:26 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 0.3.0.9008 --- .pre-commit-config.yaml | 2 +- DESCRIPTION | 4 ++-- NEWS.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index edc5fc459..63a07d3d2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/lorenzwalthert/precommit - rev: v0.4.1 + rev: v0.4.2 hooks: - id: style-files name: Style code with `styler` diff --git a/DESCRIPTION b/DESCRIPTION index 2d14d3d9a..190de8b63 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: teal.modules.general Title: General Modules for 'teal' Applications -Version: 0.3.0.9007 -Date: 2024-04-10 +Version: 0.3.0.9008 +Date: 2024-04-17 Authors@R: c( person("Dawid", "Kaledkowski", , "dawid.kaledkowski@roche.com", role = c("aut", "cre")), person("Pawel", "Rucki", , "pawel.rucki@roche.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index d601cd86d..3e849c1a7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# teal.modules.general 0.3.0.9007 +# teal.modules.general 0.3.0.9008 # teal.modules.general 0.3.0