Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename teal_data_module.R functions #1430

Merged
merged 21 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d861556
Internal srv_teal_data change
llrs-roche Dec 13, 2024
810c385
Rename {ui,srv}_teal_data to {ui,srv}_teal_data_module.
llrs-roche Dec 16, 2024
874aaf1
rename on srv_validate_reactive_teal_data
llrs-roche Dec 16, 2024
78499d9
Update text message
llrs-roche Dec 16, 2024
3e0eea9
Fix test failures
llrs-roche Dec 16, 2024
49823e6
Merge branch '1323_renames_teal_data_modules@main' of https://github.…
llrs-roche Dec 16, 2024
6868ae2
Remove ui_teal_data and srv_teal_data in favor of ui_teal_data_module…
llrs-roche Dec 17, 2024
74c1537
[skip style] [skip vbump] Restyle files
github-actions[bot] Dec 17, 2024
9338f9b
Fix style
llrs-roche Dec 17, 2024
04a4802
Merge branch '1323_renames_teal_data_modules@main' of https://github.…
llrs-roche Dec 17, 2024
7009e89
Replace teal_data_r, teal_data_rv, and data_rv to data
llrs-roche Dec 18, 2024
637723c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Dec 18, 2024
14fa40b
Document parameter changes
llrs-roche Dec 18, 2024
f1701ba
Merged origin/1323_renames_teal_data_modules@main into 1323_renames_t…
llrs-roche Dec 18, 2024
3e0e419
Replace two more argument
llrs-roche Dec 18, 2024
4d00e74
Remove indentation of parameters
llrs-roche Dec 18, 2024
646eaca
Remove comment
llrs-roche Dec 18, 2024
ba31b42
Replace reactive check for the internal function
llrs-roche Dec 18, 2024
3e38b10
Avoid name conflict
llrs-roche Dec 18, 2024
ed97041
Adopt latest feedback
llrs-roche Dec 18, 2024
9d2e771
Merge branch 'main' into 1323_renames_teal_data_modules@main
m7pr Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
# 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
26 changes: 13 additions & 13 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,7 +257,7 @@ 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()
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({
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
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
32 changes: 19 additions & 13 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@
NULL

#' @rdname module_teal_data
ui_teal_data <- function(id, data_module = function(id) NULL) {
#' @aliases ui_teal_data
#' @note
#' `ui_teal_data_module` was renamed from `ui_teal_data`.
ui_teal_data_module <- function(id, data_module = function(id) NULL) {
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_string(id)
checkmate::assert_function(data_module, args = "id")
ns <- NS(id)
Expand All @@ -49,23 +52,26 @@ ui_teal_data <- function(id, data_module = function(id) NULL) {
}

#' @rdname module_teal_data
srv_teal_data <- function(id,
data_module = function(id) NULL,
modules = NULL,
validate_shiny_silent_error = TRUE,
is_transform_failed = reactiveValues()) {
#' @aliases srv_teal_data
#' @note
#' `srv_teal_data_module` was renamed from `srv_teal_data`.
srv_teal_data_module <- function(id,
data_module = function(id) NULL,
modules = NULL,
validate_shiny_silent_error = TRUE,
is_transform_failed = reactiveValues()) {
checkmate::assert_string(id)
checkmate::assert_function(data_module, args = "id")
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"), null.ok = TRUE)
checkmate::assert_class(is_transform_failed, "reactivevalues")

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_teal_data initializing.")
logger::log_debug("srv_teal_data_module initializing.")
is_transform_failed[[id]] <- FALSE
data_out <- data_module(id = "data")
data_handled <- reactive(tryCatch(data_out(), error = function(e) e))
observeEvent(data_handled(), {
if (!inherits(data_handled(), "teal_data")) {
module_out <- data_module(id = "data")
try_module_out <- reactive(tryCatch(module_out(), error = function(e) e))
observeEvent(try_module_out(), {
if (!inherits(try_module_out(), "teal_data")) {
is_transform_failed[[id]] <- TRUE
} else {
is_transform_failed[[id]] <- FALSE
Expand All @@ -89,7 +95,7 @@ srv_teal_data <- function(id,

srv_validate_reactive_teal_data(
"validate",
data = data_handled,
data = try_module_out,
modules = modules,
validate_shiny_silent_error = validate_shiny_silent_error,
hide_validation_error = is_previous_failed
Expand Down Expand Up @@ -126,7 +132,7 @@ 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
# 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)
Expand Down
6 changes: 5 additions & 1 deletion R/module_transform_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ ui_transform_teal_data <- function(id, transformators, class = "well") {

#' @export
#' @rdname module_transform_data
srv_transform_teal_data <- function(id, data, transformators, modules = NULL, is_transform_failed = reactiveValues()) {
srv_transform_teal_data <- function(id,
data,
transformators,
modules = NULL,
is_transform_failed = reactiveValues()) {
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_string(id)
assert_reactive(data)
checkmate::assert_class(modules, "teal_module", null.ok = TRUE)
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
1 change: 1 addition & 0 deletions man/TealReportCard.Rd

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

6 changes: 3 additions & 3 deletions man/module_filter_data.Rd

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

11 changes: 9 additions & 2 deletions man/module_teal_data.Rd

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

10 changes: 5 additions & 5 deletions man/module_teal_module.Rd

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

Loading