Skip to content

Commit

Permalink
simplify logic for reactive_data validation
Browse files Browse the repository at this point in the history
  • Loading branch information
m7pr committed Sep 2, 2024
1 parent 7621a6a commit 6f8217f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
20 changes: 7 additions & 13 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,12 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
data_rv <- reactive(tryCatch(data(), error = function(e) e))

# there is an empty reactive cycle on init!
data_validated <-
srv_validate_silent_error("silent_error", data_rv, validate_shiny_silent_error)
srv_validate_silent_error("silent_error", data_rv, validate_shiny_silent_error)
srv_validate_qenv_error("qenv_error", data_rv)
srv_check_class_teal_data("class_teal_data", data_rv)
srv_check_shiny_warnings("shiny_warnings", data_rv, modules)

if (identical(data_validated, teal_data())) {
teal_data()
} else {
srv_validate_qenv_error("qenv_error", data_rv)

srv_check_class_teal_data("class_teal_data", data_rv)

srv_check_shiny_warnings("shiny_warnings", data_rv, modules)
data_rv
}
data_rv
})
}

Expand All @@ -141,7 +134,7 @@ srv_validate_silent_error <- function(id, data, validate_shiny_silent_error) {
output$error <- renderUI({
if (inherits(data(), "shiny.silent.error") && identical(data()$message, "")) {
if (!validate_shiny_silent_error) {
return(teal_data())
return(NULL)
} else {
validate(
need(
Expand All @@ -156,6 +149,7 @@ srv_validate_silent_error <- function(id, data, validate_shiny_silent_error) {
}
}
})

})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-shinytest2-filter_panel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
testthat::skip_if_not_installed("shinytest2")
testthat::skip_if_not_installed("rvest")

testthat::test_that("e2e: module content is updated when a data is filtered in filter panel", {
testthat::test_that("e2e: module content is updated when data is filtered in filter panel", {
skip_if_too_deep(5)
app <- TealAppDriver$new(
data = simple_teal_data(),
Expand Down

0 comments on commit 6f8217f

Please sign in to comment.