Skip to content

Commit

Permalink
post merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Oct 30, 2024
1 parent dfce86b commit 1c75925
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 154 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export(reporter_previewer_module)
export(set_datanames)
export(show_rcode_modal)
export(srv_teal)
export(srv_teal_transform_module)
export(srv_teal_with_splash)
export(srv_transform_data)
export(tdata2env)
export(teal_data_module)
export(teal_slices)
export(teal_transform_module)
export(ui_teal)
export(ui_teal_transform_module)
export(ui_teal_with_splash)
export(ui_transform_data)
export(validate_has_data)
export(validate_has_elements)
export(validate_has_variable)
Expand Down
4 changes: 2 additions & 2 deletions R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' shinyApp(app$ui, app$server)
#' }
#' @export
example_module <- function(label = "example teal module", datanames = "all", transformers = list()) {
example_module <- function(label = "example teal module", datanames = "all", transforms = list()) {
checkmate::assert_string(label)
ans <- module(
label,
Expand Down Expand Up @@ -59,7 +59,7 @@ example_module <- function(label = "example teal module", datanames = "all", tra
)
},
datanames = datanames,
transformers = transformers
transforms = transforms
)
attr(ans, "teal_bookmarkable") <- TRUE
ans
Expand Down
2 changes: 1 addition & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ init <- function(data,
}

is_modules_ok <- check_modules_datanames(modules, ls(teal.code::get_env(data)))
if (!isTRUE(is_modules_ok) && length(unlist(extract_transformers(modules))) == 0) {
if (!isTRUE(is_modules_ok) && length(unlist(extract_transforms(modules))) == 0) {
lapply(is_modules_ok$string, warning, call. = FALSE)
}

Expand Down
31 changes: 13 additions & 18 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
ui_teal <- tagList(
shinyjs::hidden(
tags$div(
id = ns("transformer_failure_info"),
id = ns("transform_failure_info"),
class = "teal_validated",
div(
class = "teal-output-warning",
"One of transformers failed. Please fix and continue."
"One of transforms failed. Please fix and continue."
)
)
),
Expand All @@ -125,10 +125,7 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
width = 3,
ui_data_summary(ns("data_summary")),
ui_filter_data(ns("filter_panel")),
if (length(modules$transformers) > 0 && !isTRUE(attr(modules$transformers, "custom_ui"))) {
ui_teal_transform_module(ns("data_transform"), transforms = modules$transformers, class = "well")
},
ui_transform_data(ns("data_transform"), transformers = modules$transformers, class = "well"),
ui_transform_data(ns("data_transform"), transforms = modules$transforms, class = "well"),
class = "teal_secondary_col"
)
)
Expand Down Expand Up @@ -263,27 +260,25 @@ srv_teal_module.teal_module <- function(id,
data_rv = data_rv,
is_active = is_active
)
is_transformer_failed <- reactiveValues()
is_transform_failed <- reactiveValues()
transformed_teal_data <- srv_transform_data(
"data_transform",
data = filtered_teal_data,
transformers = modules$transformers,
transforms = modules$transforms,
modules = modules,
is_transformer_failed = is_transformer_failed
is_transform_failed = is_transform_failed
)
any_transformer_failed <- reactive({
any(unlist(reactiveValuesToList(is_transformer_failed)))
any_transform_failed <- reactive({
any(unlist(reactiveValuesToList(is_transform_failed)))
})

observeEvent(any_transformer_failed(), {
if (isTRUE(any_transformer_failed())) {
observeEvent(any_transform_failed(), {
if (isTRUE(any_transform_failed())) {
shinyjs::hide("teal_module_ui")
shinyjs::hide("validate_datanames")
shinyjs::show("transformer_failure_info")
shinyjs::show("transform_failure_info")
} else {
shinyjs::show("teal_module_ui")
shinyjs::show("validate_datanames")
shinyjs::hide("transformer_failure_info")
shinyjs::hide("transform_failure_info")
}
})

Expand All @@ -294,7 +289,7 @@ srv_teal_module.teal_module <- function(id,
.subset_teal_data(all_teal_data, module_datanames)
})

srv_validate_reactive_teal_data(
srv_check_module_datanames(
"validate_datanames",
data = module_teal_data,
modules = modules
Expand Down
2 changes: 1 addition & 1 deletion R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' performed:
#' - data loading in [`module_init_data`]
#' - data filtering in [`module_filter_data`]
#' - data transformation in [`module_teal_transform_module`]
#' - data transformation in [`module_transform_data`]
#'
#' ## Fallback on failure
#'
Expand Down
22 changes: 11 additions & 11 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#' @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
#' @param is_transformer_failed (`reactiveValues`) contains `logical` flags named after each transformer.
#' Help to determine if any previous transformer failed, so that following transformers can be disabled
#' @param is_transform_failed (`reactiveValues`) contains `logical` flags named after each transform.
#' Help to determine if any previous transform failed, so that following transforms can be disabled
#' and display a generic failure message.
#'
#' @return `reactive` `teal_data`
Expand All @@ -53,29 +53,29 @@ srv_teal_data <- function(id,
data_module = function(id) NULL,
modules = NULL,
validate_shiny_silent_error = TRUE,
is_transformer_failed = reactiveValues()) {
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_transformer_failed, "reactivevalues")
checkmate::assert_class(is_transform_failed, "reactivevalues")

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_teal_data initializing.")
is_transformer_failed[[id]] <- FALSE
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")) {
is_transformer_failed[[id]] <- TRUE
is_transform_failed[[id]] <- TRUE
} else {
is_transformer_failed[[id]] <- FALSE
is_transform_failed[[id]] <- FALSE
}
})

is_previous_failed <- reactive({
idx_this <- which(names(is_transformer_failed) == id)
is_transformer_failed_list <- reactiveValuesToList(is_transformer_failed)
idx_failures <- which(unlist(is_transformer_failed_list))
idx_this <- which(names(is_transform_failed) == id)
is_transform_failed_list <- reactiveValuesToList(is_transform_failed)
idx_failures <- which(unlist(is_transform_failed_list))
any(idx_failures < idx_this)
})

Expand Down Expand Up @@ -133,7 +133,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
output$previous_failed <- renderUI({
if (hide_validation_error()) {
shinyjs::hide("validate_messages")
tags$div("One of previous transformers failed. Please fix and continue.", class = "teal-output-warning")
tags$div("One of previous transforms failed. Please fix and continue.", class = "teal-output-warning")
} else {
shinyjs::show("validate_messages")
NULL
Expand Down
32 changes: 16 additions & 16 deletions R/module_transform_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#' @return `reactive` `teal_data`
#'
#'
#' @name module_teal_transform_module
#' @name module_transform_data
NULL

#' @export
#' @rdname module_teal_transform_module
ui_teal_transform_module <- function(id, transforms, class = "well") {
#' @rdname module_transform_data
ui_transform_data <- function(id, transforms, class = "well") {
checkmate::assert_string(id)
if (length(transforms) == 0L) {
return(NULL)
Expand All @@ -25,10 +25,10 @@ ui_teal_transform_module <- function(id, transforms, class = "well") {

labels <- lapply(transforms, function(x) attr(x, "label"))
ids <- get_unique_labels(labels)
names(transformers) <- ids
names(transforms) <- ids

lapply(
names(transformers),
names(transforms),
function(name) {
child_id <- NS(id)(name)
ns <- NS(child_id)
Expand Down Expand Up @@ -70,8 +70,8 @@ ui_teal_transform_module <- function(id, transforms, class = "well") {
}

#' @export
#' @rdname module_teal_transform_module
srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_transformer_failed = reactiveValues()) {
#' @rdname module_transform_data
srv_transform_data <- function(id, data, transforms, modules = NULL, is_transform_failed = reactiveValues()) {
checkmate::assert_string(id)
assert_reactive(data)
checkmate::assert_class(modules, "teal_module", null.ok = TRUE)
Expand All @@ -90,22 +90,22 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t
Reduce(
function(data_previous, name) {
moduleServer(name, function(input, output, session) {
logger::log_debug("srv_teal_transform_module initializing for { name }.")
is_transformer_failed[[name]] <- FALSE
logger::log_debug("srv_transform_data initializing for { name }.")
is_transform_failed[[name]] <- FALSE
data_out <- transforms[[name]]$server(name, data = data_previous)
data_handled <- reactive(tryCatch(data_out(), error = function(e) e))
observeEvent(data_handled(), {
if (inherits(data_handled(), "teal_data")) {
is_transformer_failed[[name]] <- FALSE
is_transform_failed[[name]] <- FALSE
} else {
is_transformer_failed[[name]] <- TRUE
is_transform_failed[[name]] <- TRUE
}
})

is_previous_failed <- reactive({
idx_this <- which(names(is_transformer_failed) == name)
is_transformer_failed_list <- reactiveValuesToList(is_transformer_failed)
idx_failures <- which(unlist(is_transformer_failed_list))
idx_this <- which(names(is_transform_failed) == name)
is_transform_failed_list <- reactiveValuesToList(is_transform_failed)
idx_failures <- which(unlist(is_transform_failed_list))
any(idx_failures < idx_this)
})

Expand All @@ -119,7 +119,7 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t
output$error_wrapper <- renderUI({
if (is_previous_failed()) {
shinyjs::disable(transform_wrapper_id)
tags$div("One of previous transformers failed. Please fix and continue.", class = "teal-output-warning")
tags$div("One of previous transforms failed. Please fix and continue.", class = "teal-output-warning")
} else {
shinyjs::enable(transform_wrapper_id)
shiny::tagList(
Expand All @@ -133,7 +133,7 @@ srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_t
.trigger_on_success(data_handled)
})
},
x = names(transformers),
x = names(transforms),
init = data
)
})
Expand Down
32 changes: 16 additions & 16 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ setOldClass("teal_modules")
#' in a warning. Datasets with names starting with . are ignored globally unless explicitly listed
#' in `datanames`.
#'
#' # `datanames` with `transformers`
#' When transformers are specified, their `datanames` are added to the module’s `datanames`, which
#' # `datanames` with `transforms`
#' When transforms are specified, their `datanames` are added to the module’s `datanames`, which
#' changes the behavior as follows:
#' - If `module(datanames)` is `NULL` and the `transformers` have defined `datanames`, the sidebar
#' will appear showing the `transformers`' datasets, instead of being hidden.
#' - If `module(datanames)` is set to specific values and any `transformer` has `datanames = "all"`,
#' - If `module(datanames)` is `NULL` and the `transforms` have defined `datanames`, the sidebar
#' will appear showing the `transforms`' datasets, instead of being hidden.
#' - If `module(datanames)` is set to specific values and any `transform` has `datanames = "all"`,
#' the module may receive extra datasets that could be unnecessary
#'
#' @param label (`character(1)`) Label shown in the navigation item for the module or module group.
Expand Down Expand Up @@ -69,14 +69,14 @@ setOldClass("teal_modules")
#' There are 2 reserved values that have specific behaviors:
#' - The keyword `"all"` includes all datasets available in the data passed to the teal application.
#' - `NULL` hides the sidebar panel completely.
#' - If `transformers` are specified, their `datanames` are automatically added to this `datanames`
#' - If `transforms` are specified, their `datanames` are automatically added to this `datanames`
#' argument.
#' @param server_args (named `list`) with additional arguments passed on to the server function.
#' @param ui_args (named `list`) with additional arguments passed on to the UI function.
#' @param x (`teal_module` or `teal_modules`) Object to format/print.
#' @param transformers (`list` of `teal_transform_module`) that will be applied to transform module's data input.
#' @param transforms (`list` of `teal_transform_module`) that will be applied to transform module's data input.
#' Each transform module UI will appear in the `teal` application, unless the `custom_ui` attribute is set on the list.
#' If so, the module developer is responsible to display the UI in the module itself. `datanames` of the `transformers`
#' If so, the module developer is responsible to display the UI in the module itself. `datanames` of the `transforms`
#' will be added to the `datanames`.
#'
#'
Expand Down Expand Up @@ -159,7 +159,7 @@ module <- function(label = "module",
datanames = "all",
server_args = NULL,
ui_args = NULL,
transformers = list()) {
transforms = list()) {
# argument checking (independent)
## `label`
checkmate::assert_string(label)
Expand Down Expand Up @@ -266,16 +266,16 @@ module <- function(label = "module",
)
}

## `transformers`
if (inherits(transformers, "teal_transform_module")) {
transformers <- list(transformers)
## `transforms`
if (inherits(transforms, "teal_transform_module")) {
transforms <- list(transforms)
}
checkmate::assert_list(transformers, types = "teal_transform_module")
transformer_datanames <- unlist(lapply(transformers, attr, "datanames"))
checkmate::assert_list(transforms, types = "teal_transform_module")
transform_datanames <- unlist(lapply(transforms, attr, "datanames"))
combined_datanames <- if (identical(datanames, "all")) {
"all"
} else {
union(datanames, transformer_datanames)
union(datanames, transform_datanames)
}

structure(
Expand All @@ -286,7 +286,7 @@ module <- function(label = "module",
datanames = combined_datanames,
server_args = server_args,
ui_args = ui_args,
transformers = transformers
transforms = transforms
),
class = "teal_module"
)
Expand Down
Loading

0 comments on commit 1c75925

Please sign in to comment.