Skip to content

WIP: Modular validation in teal and teal_modules #1509

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

Draft
wants to merge 51 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
da34ae4
feat: manual modules
averissimo Mar 28, 2025
738dd69
feat: stable factory creation
averissimo Mar 28, 2025
b6b72aa
broken: shinysilent not triggering
averissimo Mar 28, 2025
2527887
fix: problem with shiny.silent.error id name
averissimo Mar 31, 2025
9708385
chore: cleanup
averissimo Mar 31, 2025
4ec7ef6
chore: rename ongoing
averissimo Mar 31, 2025
26e9624
chore: remove null coalesce operator that is no longer used
averissimo Mar 31, 2025
4d25b08
chore: cleanup
averissimo Mar 31, 2025
ef5859f
chore: adds comments and remove single factory function
averissimo Mar 31, 2025
f8d9ea4
chore: remove print statements
averissimo Mar 31, 2025
b9ddaee
visual: cleanup and better messages
averissimo Mar 31, 2025
abe4a18
style: improve look of messages using blockquote and em
averissimo Apr 1, 2025
7ebaa4e
chore: remove extra comments and functions
averissimo Apr 1, 2025
ccd78f6
feat: cleanup
averissimo Apr 3, 2025
4a8bfaa
cleanup: comment cleanup
averissimo Apr 3, 2025
c99f7df
cleanup: move module factory to bottom of file
averissimo Apr 3, 2025
7f9c79c
cleanup: re-generate docs
averissimo Apr 3, 2025
efb2c80
style: minor corrections and converts to bslib
averissimo Apr 3, 2025
e3c4c63
feat: abstract validation UI function
averissimo Apr 3, 2025
4f15db5
feat: unifying
averissimo Apr 4, 2025
508ad4f
cleanup: remove unused code
averissimo Apr 4, 2025
8a4caf7
cleanup: minor
averissimo Apr 4, 2025
6b7be64
cleanup: remove teal_module_data code that is no longer used
averissimo Apr 4, 2025
1e9696d
docs: rearrange some docs
averissimo Apr 4, 2025
9a547e2
cleanup: small optimizations
averissimo Apr 4, 2025
6373a30
cleanup: consistent call to show/hide
averissimo Apr 4, 2025
df110b4
cleanup: remove debugging UI elements
averissimo Apr 4, 2025
8df11e7
fix: too much cleanup
averissimo Apr 4, 2025
e3a4f50
feat: use of srv_ and ui_ to validate instead of list
averissimo Apr 7, 2025
2772337
feat: use bquote and splicing
averissimo Apr 8, 2025
6ea756e
feat: improve on stop_on_first implementation
averissimo Apr 8, 2025
a7b81fa
chore: move function to oneliner
averissimo Apr 8, 2025
0b31102
chore: minor cleanup
averissimo Apr 8, 2025
45ff32c
chore: fix linter problems
averissimo Apr 8, 2025
0fe809d
docs: remove export
averissimo Apr 8, 2025
25b397a
docs: update
averissimo Apr 8, 2025
8c2fac1
docs: typos
averissimo Apr 8, 2025
ac5c67a
docs: out of order
averissimo Apr 8, 2025
47dd8eb
feat: support for in-module validation
averissimo Apr 8, 2025
ed10c4d
fix: decorated behavior
averissimo Apr 8, 2025
f2341d1
fix: tentative solution for decorated failed original data
averissimo Apr 8, 2025
a3b3afd
feat: disable transforms/decorators and show info message when top-le…
averissimo Apr 8, 2025
8ac867e
chore: improve message
averissimo Apr 9, 2025
5fbb215
fix: remove browser
averissimo Apr 21, 2025
6f5fe25
fix: blurred UI
averissimo May 7, 2025
f52de2b
style: border on accordion with error messages
averissimo May 7, 2025
62b53ad
fix: condition
averissimo May 7, 2025
308e80a
fix: condition
averissimo May 7, 2025
8d86b10
fix: issues with disabling accordions
averissimo May 7, 2025
640a890
revert: changes moved to #1515
averissimo May 8, 2025
c53e820
Merge branch 'main' into 1322_validation@main
averissimo May 9, 2025
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ Collate:
'module_session_info.R'
'module_snapshot_manager.R'
'module_teal.R'
'module_teal_data.R'
'module_teal_lockfile.R'
'module_teal_with_splash.R'
'module_transform_data.R'
'module_validate.R'
'reporter_previewer_module.R'
'show_rcode_modal.R'
'tdata.R'
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 @@ -20,7 +20,7 @@
#' lies in data control: the first method involves external control, while the second method
#' involves control from a custom module within the app.
#'
#' For more details, see [`module_teal_data`].
#' For more details, see [`teal_data_module`].
#'
#' @inheritParams module_teal
#'
Expand Down
41 changes: 13 additions & 28 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,9 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
args <- c(list(id = ns("module")), modules$ui_args)

ui_teal <- tags$div(
shinyjs::hidden(
tags$div(
id = ns("transform_failure_info"),
class = "teal_validated",
div(
class = "teal-output-warning",
"One of transformators failed. Please check its inputs."
)
)
),
ui_module_validate(ns("validation")),
tags$div(
id = ns("teal_module_ui"),
tags$div(
class = "teal_validated",
ui_check_module_datanames(ns("validate_datanames"))
),
do.call(what = modules$ui, args = args, quote = TRUE)
)
)
Expand Down Expand Up @@ -348,29 +335,27 @@ srv_teal_module.teal_module <- function(id,
any(unlist(reactiveValuesToList(is_transform_failed)))
})

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

module_teal_data <- reactive({
req(inherits(transformed_teal_data(), "teal_data"))
all_teal_data <- transformed_teal_data()
module_datanames <- .resolve_module_datanames(data = all_teal_data, modules = modules)
all_teal_data[c(module_datanames, ".raw_data")]
})

srv_check_module_datanames(
"validate_datanames",
data = module_teal_data,
modules = modules
srv_module_validate_datanames(
"validation",
x = module_teal_data,
modules = modules,
show_warn = any_transform_failed,
message_warn = "One of the transformators failed. Please check its inputs."
)

observe({ # Blur and disable main module UI when there are errors with reactive teal_data
shinyjs::show("teal_module_ui")
shinyjs::toggleClass("teal_module_ui", "blurred", condition = any_transform_failed())
shinyjs::toggleState("teal_module_ui", condition = !any_transform_failed())
})

summary_table <- srv_data_summary("data_summary", module_teal_data)

observeEvent(input$data_summary_toggle, {
Expand Down
31 changes: 16 additions & 15 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,10 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {

data_handled <- srv_init_data("data", data = data)

validate_ui <- tags$div(
id = session$ns("validate_messages"),
class = "teal_validated",
ui_check_class_teal_data(session$ns("class_teal_data")),
ui_validate_error(session$ns("silent_error")),
ui_check_module_datanames(session$ns("datanames_warning"))
validate_ui <- ui_module_validate(session$ns("validation"))
srv_module_validate_teal_module(
"validation", x = data_handled, validate_shiny_silent_error = FALSE, modules = modules
)
srv_check_class_teal_data("class_teal_data", data_handled)
srv_validate_error("silent_error", data_handled, validate_shiny_silent_error = FALSE)
srv_check_module_datanames("datanames_warning", data_handled, modules)

data_validated <- .trigger_on_success(data_handled)

Expand Down Expand Up @@ -181,8 +175,6 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
})
}



if (inherits(data, "teal_data_module")) {
setBookmarkExclude(c("teal_modules-active_tab"))
bslib::nav_insert(
Expand All @@ -192,10 +184,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
bslib::nav_panel(
title = icon("fas fa-database"),
value = "teal_data_module",
tags$div(
ui_init_data(session$ns("data")),
validate_ui
)
tags$div(validate_ui, ui_init_data(session$ns("data")))
)
)

Expand Down Expand Up @@ -234,3 +223,15 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {

invisible(NULL)
}

.trigger_on_success <- function(data) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from deleted file

out <- reactiveVal(NULL)
observeEvent(data(), {
if (inherits(data(), "teal_data")) {
if (!identical(data(), out())) {
out(data())
}
}
})
out
}
252 changes: 0 additions & 252 deletions R/module_teal_data.R

This file was deleted.

Loading