Skip to content

Commit

Permalink
Replace teal_data_r, teal_data_rv, and data_rv to data
Browse files Browse the repository at this point in the history
  • Loading branch information
llrs-roche committed Dec 18, 2024
1 parent 04a4802 commit 7009e89
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ example_module <- function(label = "example teal module",

table_data_decorated_no_print <- srv_transform_teal_data(
"decorate",
teal_data_r = table_data,
data = table_data,
transformators = decorators
)
table_data_decorated <- reactive(within(req(table_data_decorated_no_print()), expr = object))
Expand Down
10 changes: 5 additions & 5 deletions R/module_filter_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ui_filter_data <- function(id) {
}

#' @rdname module_filter_data
srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active) {
srv_filter_data <- function(id, datasets, active_datanames, data, is_active) {
assert_reactive(datasets)
moduleServer(id, function(input, output, session) {
active_corrected <- reactive(intersect(active_datanames(), datasets()$datanames()))
Expand All @@ -42,10 +42,10 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)
})
})

trigger_data <- .observe_active_filter_changed(datasets, is_active, active_corrected, data_rv)
trigger_data <- .observe_active_filter_changed(datasets, is_active, active_corrected, data)

eventReactive(trigger_data(), {
.make_filtered_teal_data(modules, data = data_rv(), datasets = datasets(), datanames = active_corrected())
.make_filtered_teal_data(modules, data = data(), datasets = datasets(), datanames = active_corrected())
})
})
}
Expand All @@ -69,12 +69,12 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)
}

#' @rdname module_filter_data
.observe_active_filter_changed <- function(datasets, is_active, active_datanames, data_rv) {
.observe_active_filter_changed <- function(datasets, is_active, active_datanames, data) {
previous_signature <- reactiveVal(NULL)
filter_changed <- reactive({
req(inherits(datasets(), "FilteredData"))
new_signature <- c(
teal.code::get_code(data_rv()),
teal.code::get_code(data()),
.get_filter_expr(datasets = datasets(), datanames = active_datanames())
)
if (!identical(previous_signature(), new_signature)) {
Expand Down
2 changes: 1 addition & 1 deletion R/module_init_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ srv_init_data <- function(id, data) {

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_data initializing.")
# data_rv contains teal_data object
# data contains teal_data object
# either passed to teal::init or returned from teal_data_module
data_out <- if (inherits(data, "teal_data_module")) {
output$data <- renderUI(data$ui(id = session$ns("teal_data_module")))
Expand Down
28 changes: 14 additions & 14 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#'
#' @inheritParams module_teal
#'
#' @param data_rv (`reactive` returning `teal_data`)
#' @param data (`reactive` returning `teal_data`)
#'
#' @param slices_global (`reactiveVal` returning `modules_teal_slices`)
#' see [`module_filter_manager`]
Expand Down Expand Up @@ -138,15 +138,15 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {

#' @rdname module_teal_module
srv_teal_module <- function(id,
data_rv,
data,
modules,
datasets = NULL,
slices_global,
reporter = teal.reporter::Reporter$new(),
data_load_status = reactive("ok"),
is_active = reactive(TRUE)) {
checkmate::assert_string(id)
assert_reactive(data_rv)
assert_reactive(data)
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"))
assert_reactive(datasets, null.ok = TRUE)
checkmate::assert_class(slices_global, ".slicesGlobal")
Expand All @@ -158,7 +158,7 @@ srv_teal_module <- function(id,
#' @rdname module_teal_module
#' @export
srv_teal_module.default <- function(id,
data_rv,
data,
modules,
datasets = NULL,
slices_global,
Expand All @@ -171,7 +171,7 @@ srv_teal_module.default <- function(id,
#' @rdname module_teal_module
#' @export
srv_teal_module.teal_modules <- function(id,
data_rv,
data,
modules,
datasets = NULL,
slices_global,
Expand Down Expand Up @@ -201,7 +201,7 @@ srv_teal_module.teal_modules <- function(id,
function(module_id) {
srv_teal_module(
id = module_id,
data_rv = data_rv,
data = data,
modules = modules$children[[module_id]],
datasets = datasets,
slices_global = slices_global,
Expand All @@ -223,7 +223,7 @@ srv_teal_module.teal_modules <- function(id,
#' @rdname module_teal_module
#' @export
srv_teal_module.teal_module <- function(id,
data_rv,
data,
modules,
datasets = NULL,
slices_global,
Expand All @@ -235,13 +235,13 @@ srv_teal_module.teal_module <- function(id,
module_out <- reactiveVal()

active_datanames <- reactive({
.resolve_module_datanames(data = data_rv(), modules = modules)
.resolve_module_datanames(data = data(), modules = modules)
})
if (is.null(datasets)) {
datasets <- eventReactive(data_rv(), {
req(inherits(data_rv(), "teal_data"))
datasets <- eventReactive(data(), {
req(inherits(data(), "teal_data"))
logger::log_debug("srv_teal_module@1 initializing module-specific FilteredData")
teal_data_to_filtered_data(data_rv(), datanames = active_datanames())
teal_data_to_filtered_data(data(), datanames = active_datanames())
})
}

Expand All @@ -257,13 +257,13 @@ srv_teal_module.teal_module <- function(id,
"filter_panel",
datasets = datasets,
active_datanames = active_datanames,
data_rv = data_rv,
data = data,
is_active = is_active
)
is_transform_failed <- reactiveValues()
transformed_teal_data <- srv_transform_teal_data(
"data_transform",
teal_data_r = filtered_teal_data,
data = filtered_teal_data,
transformators = modules$transformators,
modules = modules,
is_transform_failed = is_transform_failed
Expand Down Expand Up @@ -346,7 +346,7 @@ srv_teal_module.teal_module <- function(id,
}

.resolve_module_datanames <- function(data, modules) {
stopifnot("data_rv must be teal_data object." = inherits(data, "teal_data"))
stopifnot("data must be teal_data object." = inherits(data, "teal_data"))
if (is.null(modules$datanames) || identical(modules$datanames, "all")) {
names(data)
} else {
Expand Down
12 changes: 6 additions & 6 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {

data_validated <- .trigger_on_success(data_pulled)

data_rv <- reactive({
data <- reactive({
req(inherits(data_validated(), "teal_data"))
is_filter_ok <- check_filter_datanames(filter, names(data_validated()))
if (!isTRUE(is_filter_ok)) {
Expand All @@ -226,10 +226,10 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
})

datasets_rv <- if (!isTRUE(attr(filter, "module_specific"))) {
eventReactive(data_rv(), {
req(inherits(data_rv(), "teal_data"))
eventReactive(data(), {
req(inherits(data(), "teal_data"))
logger::log_debug("srv_teal@1 initializing FilteredData")
teal_data_to_filtered_data(data_rv())
teal_data_to_filtered_data(data())
})
}

Expand All @@ -252,7 +252,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
)

if (attr(data, "once")) {
observeEvent(data_rv(), once = TRUE, {
observeEvent(data(), once = TRUE, {
logger::log_debug("srv_teal@2 removing data tab.")
# when once = TRUE we pull data once and then remove data tab
removeTab("teal_modules-active_tab", target = "teal_data_module")
Expand All @@ -271,7 +271,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
slices_global <- methods::new(".slicesGlobal", filter, module_labels)
modules_output <- srv_teal_module(
id = "teal_modules",
data_rv = data_rv,
data = data,
datasets = datasets_rv,
modules = modules,
slices_global = slices_global,
Expand Down
16 changes: 8 additions & 8 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' (except error 1).
#'
#' @param id (`character(1)`) Module id
#' @param teal_data_r (`reactive teal_data`)
#' @param data (`reactive teal_data`)
#' @param data_module (`teal_data_module`)
#' @param modules (`teal_modules` or `teal_module`) For `datanames` validation purpose
#' @param validate_shiny_silent_error (`logical`) If `TRUE`, then `shiny.silent.error` is validated and
Expand Down Expand Up @@ -95,7 +95,7 @@ srv_teal_data_module <- function(id,

srv_validate_reactive_teal_data(
"validate",
teal_data_r = try_module_out,
data = try_module_out,
modules = modules,
validate_shiny_silent_error = validate_shiny_silent_error,
hide_validation_error = is_previous_failed
Expand Down Expand Up @@ -123,7 +123,7 @@ ui_validate_reactive_teal_data <- function(id) {

#' @rdname module_teal_data
srv_validate_reactive_teal_data <- function(id, # nolint: object_length
teal_data_r,
data,
modules = NULL,
validate_shiny_silent_error = FALSE,
hide_validation_error = reactive(FALSE)) {
Expand All @@ -132,10 +132,10 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
checkmate::assert_flag(validate_shiny_silent_error)

moduleServer(id, function(input, output, session) {
# there is an empty reactive cycle on `init` and `data_rv` has `shiny.silent.error` class
srv_validate_error("silent_error", teal_data_r, validate_shiny_silent_error)
srv_check_class_teal_data("class_teal_data", teal_data_r)
srv_check_module_datanames("shiny_warnings", teal_data_r, modules)
# there is an empty reactive cycle on `init` and `data` has `shiny.silent.error` class
srv_validate_error("silent_error", data, validate_shiny_silent_error)
srv_check_class_teal_data("class_teal_data", data)
srv_check_module_datanames("shiny_warnings", data, modules)
output$previous_failed <- renderUI({
if (hide_validation_error()) {
shinyjs::hide("validate_messages")
Expand All @@ -146,7 +146,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
}
})

.trigger_on_success(teal_data_r)
.trigger_on_success(data)
})
}

Expand Down
8 changes: 4 additions & 4 deletions R/module_transform_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ ui_transform_teal_data <- function(id, transformators, class = "well") {
#' @export
#' @rdname module_transform_data
srv_transform_teal_data <- function(id,
teal_data_r,
data,
transformators,
modules = NULL,
is_transform_failed = reactiveValues()) {
checkmate::assert_string(id)
assert_reactive(teal_data_r)
assert_reactive(data)
checkmate::assert_class(modules, "teal_module", null.ok = TRUE)
if (length(transformators) == 0L) {
return(teal_data_r)
return(data)
}
if (inherits(transformators, "teal_transform_module")) {
transformators <- list(transformators)
Expand Down Expand Up @@ -146,7 +146,7 @@ srv_transform_teal_data <- function(id,
})
},
x = names(transformators),
init = teal_data_r
init = data
)
module_output
})
Expand Down
10 changes: 5 additions & 5 deletions R/teal_data_module-eval_code.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ setMethod("eval_code", signature = c("teal_data_module", "character"), function(
},
server = function(id) {
moduleServer(id, function(input, output, session) {
teal_data_rv <- object$server("mutate_inner")
td <- eventReactive(teal_data_rv(),
data <- object$server("mutate_inner")
td <- eventReactive(data(),
{
if (inherits(teal_data_rv(), c("teal_data", "qenv.error"))) {
eval_code(teal_data_rv(), code)
if (inherits(data(), c("teal_data", "qenv.error"))) {
eval_code(data(), code)
} else {
teal_data_rv()
data()
}
},
ignoreNULL = FALSE
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-teal_transform_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ testthat::describe("make_teal_transform_server produces a valid teal_transform_m
app = srv_transform_teal_data,
args = list(
id = "test",
teal_data_r = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
data = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
transformators = output_decorator
),
expr = {
Expand All @@ -35,7 +35,7 @@ testthat::describe("make_teal_transform_server produces a valid teal_transform_m
app = srv_transform_teal_data,
args = list(
id = "test",
teal_data_r = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
data = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
transformators = output_decorator
),
expr = {
Expand Down Expand Up @@ -68,7 +68,7 @@ testthat::test_that(
app = srv_transform_teal_data,
args = list(
id = initial_id,
teal_data_r = reactive(within(teal_data(), iris <- iris)),
data = reactive(within(teal_data(), iris <- iris)),
transformators = ttm
),
expr = {
Expand Down

0 comments on commit 7009e89

Please sign in to comment.