Skip to content
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

1304 handover error@main #1341

Merged
merged 110 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 109 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
e622e01
feat: handle errors for data inputs
vedhav Aug 28, 2024
df1a849
chore: remove unused arg
vedhav Aug 28, 2024
88b82f1
chore: remove unwanted reactives and tryCatch
vedhav Aug 28, 2024
cb8354e
Update R/module_teal.R
vedhav Aug 28, 2024
d24f9b9
fix: fail when app is initialised with `qnev.error` object
vedhav Aug 28, 2024
94a1dcd
fix: `srv_teal` should not accept `qenv.error`
vedhav Aug 28, 2024
fd42f4c
chore: simplify logic by using `req`
vedhav Aug 28, 2024
e0bac03
remove "error" from qenv.error check
m7pr Aug 28, 2024
17671ad
fix: pass the proper data
vedhav Aug 28, 2024
ced492a
fix: add validation for transform failure
vedhav Aug 28, 2024
5405f82
Merge branch 'main' into 1304-handle-data-inputs@main
vedhav Aug 28, 2024
eaccd79
chore: move the validation to a separate module
vedhav Aug 28, 2024
4208bd1
feat: decorate error and warning messages
vedhav Aug 28, 2024
3f8798f
fix: return TRUE when valid datanames are present in all modules
vedhav Aug 28, 2024
0cd180f
chore: minor changes
vedhav Aug 28, 2024
c130e3c
chore: update docs
vedhav Aug 29, 2024
2e3dd81
chore: fix some tests
vedhav Aug 29, 2024
a9f1fac
chore: not using internal function in tests
vedhav Aug 29, 2024
735a322
fix: trigger the module only when it is active
vedhav Aug 30, 2024
9ca7c93
Update tests/testthat/test-module_teal.R
vedhav Aug 30, 2024
227b285
Update tests/testthat/test-module_teal.R
vedhav Aug 30, 2024
e0fd3c2
chore: fix the broken tests
vedhav Aug 30, 2024
c3ea231
Update R/utils.R
vedhav Aug 30, 2024
5dabd5b
1304 extensions - wrap repetitive code into modules (#1338)
m7pr Sep 3, 2024
0d66e86
combine if statements
m7pr Sep 3, 2024
7673c2d
WIP
gogonzo Sep 4, 2024
31eb23d
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 4, 2024
64ced0e
comments
gogonzo Sep 4, 2024
8cfb120
return datanames
m7pr Sep 4, 2024
ace22e7
bring back .fallback_on_failure
m7pr Sep 4, 2024
34240d3
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 4, 2024
03f8009
rewrite fallback_on_failure
m7pr Sep 5, 2024
084014b
Merge branch '1304-handover-error@main' of https://github.com/insight…
m7pr Sep 5, 2024
b0f6001
update documentation
m7pr Sep 5, 2024
530fb17
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 5, 2024
690d837
failure_callback approach
m7pr Sep 9, 2024
12ddddc
WIP saving progress on attempts to disable transformers based on is_t…
m7pr Sep 10, 2024
1c1f496
temporary is_previous_failed reactive
m7pr Sep 11, 2024
ee152e5
fix
dependabot-preview[bot] Sep 11, 2024
2a4f2d6
delete
dependabot-preview[bot] Sep 11, 2024
c647f5d
do not show srv_validate_reactive_teal_data warnings when there is an…
m7pr Sep 11, 2024
33fa693
documentation cleanup
m7pr Sep 11, 2024
cff2800
Merge branch 'failure_callback@1304-handover-error@main' into 1304-ha…
dependabot-preview[bot] Sep 12, 2024
b4e5685
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 12, 2024
ddd7698
fixes
dependabot-preview[bot] Sep 12, 2024
27f740b
Update .github/workflows/check.yaml
m7pr Sep 12, 2024
6a5657a
Merge branch 'main' into 1304-handover-error@main
m7pr Sep 12, 2024
a4205a0
fix some tests
m7pr Sep 12, 2024
ade1b58
more tests fixed
m7pr Sep 12, 2024
7aabfad
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 12, 2024
4cf2730
bring back old documentation
m7pr Sep 12, 2024
45711bb
Update R/module_teal.R
m7pr Sep 12, 2024
a532670
add assertions on is_transformer_failed and failure_callback
m7pr Sep 12, 2024
e642f7c
Merge branch '1304-handover-error@main' of https://github.com/insight…
m7pr Sep 12, 2024
c25d3c6
Update R/module_teal_data.R
m7pr Sep 12, 2024
dc983e7
Update R/module_teal_data.R
m7pr Sep 12, 2024
57a065e
Update R/module_teal_data.R
m7pr Sep 12, 2024
8265176
bring back the removal of teal_data_module for once=TRUE
m7pr Sep 12, 2024
24a0aa9
Merge branch '1304-handover-error@main' of https://github.com/insight…
m7pr Sep 12, 2024
3692c9c
Update R/module_teal_data.R
m7pr Sep 12, 2024
f074af2
Update R/module_transform_data.R
m7pr Sep 12, 2024
71b7ce4
Update R/module_transform_data.R
m7pr Sep 12, 2024
2720e93
Update R/module_teal_data.R
m7pr Sep 12, 2024
8b7c50a
Update R/module_nested_tabs.R
m7pr Sep 12, 2024
bd96062
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 12, 2024
4031cd8
Update R/module_init_data.R
m7pr Sep 12, 2024
8bc91a5
Update R/dummy_functions.R
m7pr Sep 12, 2024
df5f26f
fix default reactiveValues
dependabot-preview[bot] Sep 13, 2024
023a63b
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 13, 2024
32792e3
- fix callback execution for multiple transformers
dependabot-preview[bot] Sep 13, 2024
84f95e8
WIP
dependabot-preview[bot] Sep 13, 2024
8d34440
todo
dependabot-preview[bot] Sep 13, 2024
d061da5
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 13, 2024
2129378
fix for setting up combined datanames for modules$datanames and trans…
m7pr Sep 13, 2024
7d121e2
Merge branch '1304-handover-error@main' of https://github.com/insight…
m7pr Sep 13, 2024
b8a1b8c
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 13, 2024
1fbb908
revert the combined_datanames change
m7pr Sep 13, 2024
b7d9ea1
revert changes in tests
m7pr Sep 13, 2024
afe6f77
WIP but is working
dependabot-preview[bot] Sep 16, 2024
e3d1169
Merge remote-tracking branch 'origin/1304-handover-error@main' into 1…
dependabot-preview[bot] Sep 16, 2024
818121f
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 16, 2024
53137a4
rename function to more precise name
dependabot-preview[bot] Sep 16, 2024
36fa1ea
WIP
dependabot-preview[bot] Sep 16, 2024
5da350e
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 16, 2024
c3a91bb
Merge remote-tracking branch 'origin/main' into 1304-handover-error@main
dependabot-preview[bot] Sep 16, 2024
0e246b8
fix empty data error
dependabot-preview[bot] Sep 16, 2024
94447c8
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 16, 2024
542c4c9
move data out from the ui
dependabot-preview[bot] Sep 16, 2024
60e4666
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 16, 2024
3d3f3f1
move tabs management to srv_teal_module
dependabot-preview[bot] Sep 16, 2024
8140004
spelling
dependabot-preview[bot] Sep 16, 2024
f09f0dc
remove unnecessary
dependabot-preview[bot] Sep 16, 2024
8b34071
remove unnecessary
dependabot-preview[bot] Sep 16, 2024
d204a83
fix shinytest2 tests
dependabot-preview[bot] Sep 17, 2024
62c952a
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 17, 2024
02e58ca
add a tab if teal_data_module
dependabot-preview[bot] Sep 17, 2024
f339e00
cleanup
dependabot-preview[bot] Sep 17, 2024
de95ac2
removeUI and insertUI in the same place
dependabot-preview[bot] Sep 17, 2024
af5eb40
Merge remote-tracking branch 'origin/main' into 1304-handover-error@main
dependabot-preview[bot] Sep 17, 2024
780a4f2
show validate ui in different places when teal_data_module is present…
dependabot-preview[bot] Sep 18, 2024
5224847
Update R/module_teal.R
m7pr Sep 18, 2024
757b1f7
Update R/module_nested_tabs.R
m7pr Sep 18, 2024
5945713
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
dependabot-preview[bot] Sep 18, 2024
6e7b316
Merge branch 'main' into 1304-handover-error@main
dependabot-preview[bot] Sep 23, 2024
360d42d
bring back removed line
dependabot-preview[bot] Sep 23, 2024
0f60d7a
more precise name/status
dependabot-preview[bot] Sep 23, 2024
c97ac2b
Merge branch 'main' into 1304-handover-error@main
dependabot-preview[bot] Sep 26, 2024
3110363
post merge fixes
dependabot-preview[bot] Sep 26, 2024
62a1347
Merge branch 'main' into 1304-handover-error@main
gogonzo Sep 30, 2024
9c1b9d6
@vedhav review
dependabot-preview[bot] Oct 2, 2024
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ S3method(srv_teal_module,default)
S3method(srv_teal_module,teal_module)
S3method(srv_teal_module,teal_modules)
S3method(ui_teal_module,default)
S3method(ui_teal_module,shiny.tag)
S3method(ui_teal_module,teal_module)
S3method(ui_teal_module,teal_modules)
S3method(within,teal_data_module)
Expand Down
1 change: 0 additions & 1 deletion R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ init <- function(data,
ui = function(request) {
ui_teal(
id = ns("teal"),
data = if (inherits(data, "teal_data_module")) data,
modules = modules,
title = title,
header = header,
Expand Down
13 changes: 11 additions & 2 deletions R/module_filter_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)
"lockEnvironment(.raw_data) #@linksto .raw_data" # this is environment and it is shared by qenvs. CAN'T MODIFY!
)
)
filtered_code <- teal.slice::get_filter_expr(datasets = datasets, datanames = datanames)
filtered_code <- .get_filter_expr(datasets = datasets, datanames = datanames)
filtered_teal_data <- .append_evaluated_code(data, filtered_code)
filtered_datasets <- sapply(datanames, function(x) datasets$get_data(x, filtered = TRUE), simplify = FALSE)
filtered_teal_data <- .append_modified_data(filtered_teal_data, filtered_datasets)
Expand All @@ -75,7 +75,7 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)
req(inherits(datasets(), "FilteredData"))
new_signature <- c(
teal.data::get_code(data_rv()),
teal.slice::get_filter_expr(datasets = datasets(), datanames = active_datanames())
.get_filter_expr(datasets = datasets(), datanames = active_datanames())
)
if (!identical(previous_signature(), new_signature)) {
previous_signature(new_signature)
Expand All @@ -100,3 +100,12 @@ srv_filter_data <- function(id, datasets, active_datanames, data_rv, is_active)

trigger_data
}

#' @rdname module_filter_data
.get_filter_expr <- function(datasets, datanames) {
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
if (length(datanames)) {
teal.slice::get_filter_expr(datasets = datasets, datanames = datanames)
} else {
NULL
}
}
110 changes: 29 additions & 81 deletions R/module_init_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,119 +25,67 @@
#' @inheritParams init
#'
#' @param data (`teal_data`, `teal_data_module`, or `reactive` returning `teal_data`)
#' The `ui` component of this module does not require `data` if `teal_data_module` is not provided.
#' The `data` argument in the `ui` is included solely for the `$ui` function of the
#' `teal_data_module`. Otherwise, it can be disregarded, ensuring that `ui_teal` does not depend on
#' the reactive data of the enclosing application.
#' The data which application will depend on.
#'
#' @return A `reactive` object that returns:
#' - `teal_data` when the object is validated
#' - `shiny.silent.error` when not validated.
#' Output of the `data`. If `data` fails then returned error is handled (after [tryCatch()]) so that
#' rest of the application can respond to this respectively.
#'
#' @rdname module_init_data
#' @name module_init_data
#' @keywords internal
NULL

#' @rdname module_init_data
ui_init_data <- function(id, data) {
ui_init_data <- function(id) {
ns <- shiny::NS(id)
shiny::div(
id = ns("content"),
style = "display: inline-block;",
if (inherits(data, "teal_data_module")) {
ui_teal_data(ns("teal_data_module"), data_module = data)
} else {
NULL
}
style = "display: inline-block; width: 100%;",
uiOutput(ns("data"))
)
}

#' @rdname module_init_data
srv_init_data <- function(id, data, modules, filter = teal_slices()) {
srv_init_data <- function(id, data) {
checkmate::assert_character(id, max.len = 1, any.missing = FALSE)
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module", "reactive", "reactiveVal"))
checkmate::assert_class(modules, "teal_modules")
checkmate::assert_class(filter, "teal_slices")
checkmate::assert_multi_class(data, c("teal_data", "teal_data_module", "reactive"))

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_data initializing.")

if (getOption("teal.show_js_log", default = FALSE)) {
shinyjs::showLog()
}

# data_rv contains teal_data object
# either passed to teal::init or returned from teal_data_module
data_validated <- if (inherits(data, "teal_data_module")) {
srv_teal_data(
"teal_data_module",
data = reactive(req(FALSE)), # to .fallback_on_failure to shiny.silent.error
data_module = data,
modules = modules,
validate_shiny_silent_error = FALSE
)
data_out <- if (inherits(data, "teal_data_module")) {
output$data <- renderUI(data$ui(id = session$ns("teal_data_module")))
data$server("teal_data_module")
} else if (inherits(data, "teal_data")) {
reactiveVal(data)
} else if (test_reactive(data)) {
.fallback_on_failure(this = data, that = reactive(req(FALSE)), label = "Reactive data")
}

if (inherits(data, "teal_data_module")) {
shinyjs::disable(selector = sprintf(".teal-body:has('#%s') .nav li a", session$ns("content")))
data
}

observeEvent(data_validated(), {
showNotification("Data loaded successfully.", duration = 5)
shinyjs::enable(selector = sprintf(".teal-body:has('#%s') .nav li a", session$ns("content")))
if (isTRUE(attr(data, "once"))) {
# Hiding the data module tab.
shinyjs::hide(
selector = sprintf(
".teal-body:has('#%s') a[data-value='teal_data_module']",
session$ns("content")
)
)
# Clicking the second tab, which is the first module.
shinyjs::runjs(
sprintf(
"document.querySelector('.teal-body:has(#%s) .nav li:nth-child(2) a').click();",
session$ns("content")
)
)
}
data_handled <- reactive({
tryCatch(data_out(), error = function(e) e)
})

is_filter_ok <- check_filter_datanames(filter, ls(teal.code::get_env(data_validated())))
if (!isTRUE(is_filter_ok)) {
showNotification(
"Some filters were not applied because of incompatibility with data. Contact app developer.",
type = "warning",
duration = 10
# We want to exclude teal_data_module elements from bookmarking as they might have some secrets
observeEvent(data_handled(), {
if (inherits(data_handled(), "teal_data")) {
app_session <- .subset2(shiny::getDefaultReactiveDomain(), "parent")
setBookmarkExclude(
session$ns(
grep(
pattern = "teal_data_module-",
x = names(reactiveValuesToList(input)),
value = TRUE
)
),
session = app_session
)
warning(is_filter_ok)
}
})

observeEvent(data_validated(), once = TRUE, {
# Excluding the ids from teal_data_module using full namespace and global shiny app session.
app_session <- .subset2(shiny::getDefaultReactiveDomain(), "parent")
setBookmarkExclude(
session$ns(
grep(
pattern = "teal_data_module-",
x = names(reactiveValuesToList(input)),
value = TRUE
)
),
session = app_session
)
})

# Adds signature protection to the datanames in the data
reactive({
req(data_validated())
.add_signature_to_data(data_validated())
})
data_handled
})
}

Expand Down
Loading
Loading