Skip to content

Commit

Permalink
Merge branch '712-tm_g_association@main' of https://github.com/insigh…
Browse files Browse the repository at this point in the history
…tsengineering/teal.modules.general into 712-tm_g_association@main
  • Loading branch information
m7pr committed Apr 18, 2024
2 parents 20505d8 + 51921e3 commit a8966f0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# teal.modules.general 0.3.0.9007
# teal.modules.general 0.3.0.9008

# teal.modules.general 0.3.0

Expand Down
2 changes: 1 addition & 1 deletion R/tm_g_bivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
66 changes: 25 additions & 41 deletions tests/testthat/helper-TealAppDriver.R
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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")
)
)
)
}
40 changes: 39 additions & 1 deletion tests/testthat/test-shinytest2-tm_g_association.R
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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()

})

0 comments on commit a8966f0

Please sign in to comment.