From 6f8217f07b42db610985f0d1448c06329bd991b3 Mon Sep 17 00:00:00 2001 From: m7pr Date: Tue, 3 Sep 2024 00:10:30 +0200 Subject: [PATCH] simplify logic for reactive_data validation --- R/module_teal_data.R | 20 +++++++------------ tests/testthat/test-shinytest2-filter_panel.R | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/R/module_teal_data.R b/R/module_teal_data.R index 73b893f28e..fc6930e95f 100644 --- a/R/module_teal_data.R +++ b/R/module_teal_data.R @@ -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 }) } @@ -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( @@ -156,6 +149,7 @@ srv_validate_silent_error <- function(id, data, validate_shiny_silent_error) { } } }) + }) } diff --git a/tests/testthat/test-shinytest2-filter_panel.R b/tests/testthat/test-shinytest2-filter_panel.R index aa65eb567d..22be061ab7 100644 --- a/tests/testthat/test-shinytest2-filter_panel.R +++ b/tests/testthat/test-shinytest2-filter_panel.R @@ -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(),