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 diff --git a/R/tm_g_bivariate.R b/R/tm_g_bivariate.R index 3349b667d..7c3fa8ee6 100644 --- a/R/tm_g_bivariate.R +++ b/R/tm_g_bivariate.R @@ -821,7 +821,7 @@ bivariate_ggplot_call <- function(x_class, Reduce(function(x, y) call("+", x, y), args) } - plot_call <- substitute(ggplot2::ggplot(data_name), env = list(data_name = as.name(data_name))) + plot_call <- substitute(ggplot(data_name), env = list(data_name = as.name(data_name))) # Single data plots if (x_class == "numeric" && y_class == "NULL") { diff --git a/tests/testthat/helper-TealAppDriver.R b/tests/testthat/helper-TealAppDriver.R index 94ad82f39..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() { @@ -27,42 +50,3 @@ simple_cdisc_data <- function(datasets = c("ADSL", "ADRS", "ADTTE")) { teal.data::join_keys(data) <- teal.data::default_cdisc_join_keys[datasets] data } - -app_driver_tm_g_association <- function() { - data <- within(teal.data::teal_data(), { - require(nestcolor) - require(ggplot2) - CO2 <- CO2 # nolint: object_name. - factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) - CO2[factors] <- lapply(CO2[factors], as.character) # nolint: object_name. - }) - teal.data::datanames(data) <- c("CO2") - - TealAppDriver$new( - data = data, - modules = tm_g_association( - ref = 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 = "Plant", - fixed = FALSE - ) - ), - vars = teal.transform::data_extract_spec( - dataname = "CO2", - select = teal.transform::select_spec( - label = "Select variables:", - choices = teal.transform::variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), - selected = "Treatment", - multiple = TRUE, - fixed = FALSE - ) - ), - ggplot2_args = teal.widgets::ggplot2_args( - labs = list(subtitle = "Plot generated by Association Module") - ) - ) - ) -} diff --git a/tests/testthat/test-shinytest2-tm_g_association.R b/tests/testthat/test-shinytest2-tm_g_association.R index e7a0bebff..9712c6be3 100644 --- a/tests/testthat/test-shinytest2-tm_g_association.R +++ b/tests/testthat/test-shinytest2-tm_g_association.R @@ -1,3 +1,42 @@ +app_driver_tm_g_association <- function() { + data <- within(teal.data::teal_data(), { + require(nestcolor) + require(ggplot2) + CO2 <- CO2 # nolint: object_name. + factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) + CO2[factors] <- lapply(CO2[factors], as.character) # nolint: object_name. + }) + teal.data::datanames(data) <- c("CO2") + + init_teal_app_driver( + data = data, + modules = tm_g_association( + ref = 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 = "Plant", + fixed = FALSE + ) + ), + vars = teal.transform::data_extract_spec( + dataname = "CO2", + select = teal.transform::select_spec( + label = "Select variables:", + choices = teal.transform::variable_choices(data[["CO2"]], c("Plant", "Type", "Treatment")), + selected = "Treatment", + multiple = TRUE, + fixed = FALSE + ) + ), + ggplot2_args = teal.widgets::ggplot2_args( + labs = list(subtitle = "Plot generated by Association Module") + ) + ) + ) +} + testthat::test_that("e2e - tm_g_association: data parameter and module label is passed properly", { skip_if_too_deep(5) @@ -52,5 +91,4 @@ testthat::test_that("e2e - tm_g_association: test if default radio buttons are c app_driver$expect_no_shiny_error() app_driver$stop() - })