WIP: Modular validation in teal and teal_modules#1509
Draft
averissimo wants to merge 51 commits intomainfrom
Draft
WIP: Modular validation in teal and teal_modules#1509averissimo wants to merge 51 commits intomainfrom
teal and teal_modules#1509averissimo wants to merge 51 commits intomainfrom
Conversation
averissimo
commented
Apr 4, 2025
| } | ||
|
|
||
|
|
||
| .trigger_on_success <- function(data) { |
Contributor
Author
There was a problem hiding this comment.
Moved from deleted file
| @@ -1,252 +0,0 @@ | |||
| #' Execute and validate `teal_data_module` | |||
Contributor
Author
There was a problem hiding this comment.
No longer used internally, deleting unless there is some use case
R/module_validate.R
Outdated
Comment on lines
310
to
325
| module_validate_teal_module <- module_validate_factory( | ||
| srv_module_check_previous_state_warn, | ||
| # Validate_error | ||
| srv_module_check_shinysilenterror, | ||
| srv_module_check_validation_error, | ||
| srv_module_check_condition, | ||
| srv_module_check_reactive, | ||
|
|
||
| srv_module_check_teal_data, | ||
| srv_module_check_datanames | ||
| ) | ||
|
|
||
| module_validate_datanames <- module_validate_factory( | ||
| srv_module_check_previous_state_warn, | ||
| srv_module_check_datanames | ||
| ) |
Contributor
Author
There was a problem hiding this comment.
There are basically 2 types of data validation groups throughout teal
We could reduce complexity of code and define the 2 module_validate_xxx manually while still keeping with low-level srv_module_check_*** functions.
R/module_validate.R
Outdated
| @@ -0,0 +1,325 @@ | |||
| #' Factory to build validate modules | |||
Contributor
Author
There was a problem hiding this comment.
Example of list generated by factory:
#> > module_validate_datanames
#> $ui
function(id) {
div(
id = NS(id, "validate_messages"),
class = "teal_validated",
tags$div(class = "messages", uiOutput(NS(id, "errors")))
)
}
#> $server
function (id, x, show_warn = reactive(FALSE), message_warn = "not defined",
modules, stop_on_first = TRUE)
{
checkmate::assert_string(id)
moduleServer(id, function(input, output, session) {
collection <- list()
collection <- append(collection, srv_module_check_previous_state_warn(x,
show_warn, message_warn))
collection <- append(collection, srv_module_check_datanames(id,
x, modules))
validate_r <- reactive({
message_collection <- Reduce(function(u, v) if (isTRUE(v()) ||
is.null(v()))
u
else append(u, list(v())), x = collection, init = list())
message_collection
})
output$errors <- renderUI({
error_class <- c("shiny.silent.error", "validation",
"error", "condition")
if (length(validate_r()) > 0) {
tagList(!!!lapply(validate_r()[1], function(.x) {
html_class <- if (isTRUE(attr(.x[1], "is_warning")) ||
isTRUE(attr(.x, "is_warning"))) {
"teal-output-warning teal-output-condition"
}
else {
"shiny-output-error teal-output-condition"
}
if (!checkmate::test_multi_class(.x, c("shiny.tag",
"shiny.tag.list"))) {
html_class <- c(html_class, "prewrap-ws")
.x <- lapply(.x, tags$p)
}
tags$div(class = html_class, tags$div(.x))
}))
}
})
x
})
}…vel data is not teal_data
Contributor
Author
|
ℹ️ Updated example app |
3 tasks
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🐻 WIP 🐻: Beware that code may break!!
Pull Request
Fixes #1322
Unified validation framework that allows to create re-usable validation modules for
tealframework as well as in modulesChanges description
srv_module_check_XXXXTRUEfor no problemmodule_validate_datanames$server)teal_data(pre-decorated) in the UI? #1421qenv.errorrequirement fromteal[Question]: qenv.error probably doesn't make sense anymore #1458Caveats
Error handling in parallelLogic should be very narrow to avoid repeated messages for the same underlying problem (such asshiny.silent.errorsvs.validationvs.generci conditions)stop_on_first = TRUEparameter for factory.Sample App to test errors