-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: main
Are you sure you want to change the base?
Conversation
@@ -234,3 +234,17 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) { | |||
|
|||
invisible(NULL) | |||
} | |||
|
|||
|
|||
.trigger_on_success <- function(data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved from deleted file
@@ -1,252 +0,0 @@ | |||
#' Execute and validate `teal_data_module` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer used internally, deleting unless there is some use case
R/module_validate.R
Outdated
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 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
ℹ️ Updated example app |
🐻 WIP 🐻: Beware that code may break!!
Pull Request
Fixes #1322
Unified validation framework that allows to create re-usable validation modules for
teal
framework as well as in modulesChanges description
srv_module_check_XXXX
TRUE
for no problemmodule_validate_datanames$server
)teal_data
(pre-decorated) in the UI? #1421qenv.error
requirement 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.errors
vs.validation
vs.generci conditions
)stop_on_first = TRUE
parameter for factory.Sample App to test errors