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

Adds decorate functionality to module output #1357

Merged
merged 198 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
b74d1f6
WIP
dependabot-preview[bot] Sep 26, 2024
6835c18
init
dependabot-preview[bot] Sep 27, 2024
9fc5923
WIP
dependabot-preview[bot] Sep 27, 2024
9bc0405
Merge branch 'main' into 1187_decorate_output@main
dependabot-preview[bot] Sep 27, 2024
9f4e6dd
[skip style] [skip vbump] Restyle files
github-actions[bot] Sep 30, 2024
fa117d1
multiple outputs
dependabot-preview[bot] Sep 30, 2024
ed29e78
Merge remote-tracking branch 'origin/main' into 1187_decorate_output@…
dependabot-preview[bot] Oct 3, 2024
c214c25
reshuffle validation of teal_transform_module
dependabot-preview[bot] Oct 4, 2024
5f7ab79
don't display UI if not specified
dependabot-preview[bot] Oct 7, 2024
898015f
Dispatch in teal_transform_module constructor
dependabot-preview[bot] Oct 8, 2024
b5cb59f
- make_teal_transform_server to simplify teal_transform_module's serv…
dependabot-preview[bot] Oct 9, 2024
30bb248
move teal_transform_module to a new file instead of keeping with teal…
dependabot-preview[bot] Oct 9, 2024
dfce86b
Merge branch 'main' into 1187_decorate_output@main
gogonzo Oct 30, 2024
1c75925
post merge fixes
gogonzo Oct 30, 2024
a92ebc9
Merge branch 'main' into 1187_decorate_output@main
gogonzo Nov 6, 2024
5894970
Merge branch 'main' into 1187_decorate_output@main
gogonzo Nov 7, 2024
b1b85d4
Merge branch 'main' into 1187_decorate_output@main
m7pr Nov 11, 2024
d2626b1
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
3cd4761
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 11, 2024
a0977eb
Update R/teal_transform_module.R
m7pr Nov 11, 2024
51e10cd
Update R/teal_transform_module.R
m7pr Nov 11, 2024
9dfce2d
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 11, 2024
e46964e
redact decorate-modules-output vignette
m7pr Nov 11, 2024
b54fd6d
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
8f03d2e
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
c2e530d
small edits to the second vignette
m7pr Nov 11, 2024
4be8b97
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
02de519
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
b09ff42
add init part to examples of teal_transform_data so it's clear where …
m7pr Nov 11, 2024
ac475e8
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
106bf4c
decorator -> decorators
m7pr Nov 11, 2024
5206bfe
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
a1888c0
Update R/teal_transform_module.R
m7pr Nov 11, 2024
4cabc0c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 11, 2024
e5e2e58
teal.data::datanames to names
m7pr Nov 11, 2024
d9bc6e7
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
f33669d
woops
m7pr Nov 11, 2024
8182e6d
ugh
m7pr Nov 11, 2024
38335b7
bring back extract_transformers
m7pr Nov 11, 2024
cabf9f2
Revert "bring back extract_transformers"
m7pr Nov 11, 2024
350d990
unify naming convention transformers->transforms
m7pr Nov 11, 2024
c36ab66
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
6eccdb8
fix 3 tests
m7pr Nov 11, 2024
6843cc8
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
bf210b4
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 11, 2024
1004af4
fix 2 more tests
m7pr Nov 11, 2024
df0b16e
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 11, 2024
5b7e901
change names of ui/srv_transform_data in vignette
m7pr Nov 12, 2024
9d82fea
fix vignette code
m7pr Nov 12, 2024
9d4eeac
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 12, 2024
e132211
remove pipe operator from vignette
m7pr Nov 12, 2024
64fbbbd
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 12, 2024
c84cbb6
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 12, 2024
64e7f5d
remove pipes, simplify example in the vignette, add skeleton tests
m7pr Nov 12, 2024
97b55af
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 12, 2024
4117417
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 12, 2024
7f1375f
Merge branch 'main' into 1187_decorate_output@main
m7pr Nov 13, 2024
f6a4513
documentation enhancemenes
m7pr Nov 13, 2024
81e1277
decorator example with DT table
m7pr Nov 13, 2024
6729e4d
update names in vignette
m7pr Nov 13, 2024
ecbf96f
extend example_module so it handles decorations
m7pr Nov 13, 2024
99c7a7c
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 13, 2024
e0bcb23
update NEWS
m7pr Nov 13, 2024
41fd9d7
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 13, 2024
cc1f7be
remove indent from format.teal_module
m7pr Nov 14, 2024
a1aaee2
fix Spell Check
m7pr Nov 14, 2024
fc596d4
missing chunk end typo
m7pr Nov 14, 2024
986a7c8
rename *_transofrm_data -> *_teal_transform_data
m7pr Nov 14, 2024
efdf8d2
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
e6c2ff0
fix pkgdown
m7pr Nov 14, 2024
f0e0605
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
875ccdb
update names in tests
m7pr Nov 14, 2024
56872ec
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 14, 2024
e86e19f
Apply suggestions from code review
m7pr Nov 14, 2024
c2bc50d
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
e14f9b1
Update NEWS.md
m7pr Nov 14, 2024
f9bdb60
@gogonzo suggestions
m7pr Nov 14, 2024
f0b87f8
change transform to transformator
m7pr Nov 14, 2024
b54ebfc
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
a90544f
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 14, 2024
d7f8366
update WORDLIST
m7pr Nov 14, 2024
d3c8830
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
0481d15
update docuemntaion
m7pr Nov 14, 2024
103ad27
change the object in example_module and document it
m7pr Nov 14, 2024
0e1d83f
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 14, 2024
e91d198
update examples
m7pr Nov 14, 2024
7576e11
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 14, 2024
8ced169
create two shinytest2 tests for decorators
m7pr Nov 14, 2024
9daa456
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
532fe73
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
40c73fd
combine decorator vignettes into one
m7pr Nov 14, 2024
a73dc58
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
80af8a2
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
5c839b5
lintr fixes
m7pr Nov 14, 2024
8bc8c10
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
3d5bc4e
rebuild docs
m7pr Nov 14, 2024
87acaec
fix one more test
m7pr Nov 14, 2024
2d7089c
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
28f17da
Update tests/testthat/test-shinytest2-decorators.R
m7pr Nov 14, 2024
8d3a465
Update R/modules.R
m7pr Nov 14, 2024
30002e1
bring back test for eventReactive value returned by teal_transform_mo…
m7pr Nov 14, 2024
0f6a2a8
merge
m7pr Nov 14, 2024
af099e8
prefix in vignette
m7pr Nov 14, 2024
37dc226
rerun docs
m7pr Nov 14, 2024
5663ca2
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Nov 14, 2024
717603d
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 14, 2024
31aa2d2
cleanup tests - remove ggplot2 examples
m7pr Nov 14, 2024
ceb97ff
Update R/dummy_functions.R
m7pr Nov 14, 2024
9ceff8b
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 14, 2024
0860bdf
fix: test with datanames validation
averissimo Nov 15, 2024
a8f1166
Merge branch 'main' into 1187_decorate_output@main
averissimo Nov 15, 2024
1f97c13
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
2bb9291
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
17afb2b
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
72e33f4
remove DT from vignette/dependencies
m7pr Nov 18, 2024
7bf54e7
Merge branch 'main' into 1187_decorate_output@main
m7pr Nov 18, 2024
6e9ae0c
change expression to language - as that's how it is documented in the…
m7pr Nov 18, 2024
0f51ce5
wrapper -> convenience function
m7pr Nov 18, 2024
5d09fcf
adjust intro
m7pr Nov 18, 2024
afbe5be
shiny::testServer tests for srv_teal_transform
m7pr Nov 18, 2024
4ba6320
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 18, 2024
2dae2b6
add pkgdown links to 1st appearance of the function in the decorators…
m7pr Nov 18, 2024
e39a883
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 18, 2024
60eec6e
be direct about which modules we talk
m7pr Nov 18, 2024
5007a82
Update R/dummy_functions.R
m7pr Nov 18, 2024
d395ac6
Update R/dummy_functions.R
m7pr Nov 18, 2024
d7c1f7e
Update R/modules.R
m7pr Nov 18, 2024
29ea4f1
change order of setnences in transofrmator vignette
m7pr Nov 18, 2024
cdf8797
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 18, 2024
9de76b9
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
f90bb77
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
75b41b9
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
1bdd159
link to teal_transform_module in transform vignettes
m7pr Nov 18, 2024
7a4778a
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 18, 2024
fd78283
Update vignettes/data-transform-as-shiny-module.Rmd
m7pr Nov 18, 2024
9e00183
Update vignettes/data-transform-as-shiny-module.Rmd
m7pr Nov 18, 2024
f329c0e
write about what is a decorator in general
m7pr Nov 18, 2024
6140ff8
Merge branch '1187_decorate_output@main' of https://github.com/insigh…
m7pr Nov 18, 2024
585a3ba
Update vignettes/decorate-module-output.Rmd
m7pr Nov 18, 2024
33b308f
fix: tests
averissimo Nov 18, 2024
44e4bc3
fix: long test name
averissimo Nov 18, 2024
134dcf4
fix: long test name
averissimo Nov 18, 2024
21d0e36
fix: namespace in tests
averissimo Nov 18, 2024
5e088eb
Merge branch 'main' into 1187_decorate_output@main
m7pr Nov 19, 2024
b91b8c0
Apply suggestions from code review
m7pr Nov 19, 2024
cbc401e
this req is not needed
m7pr Nov 19, 2024
8a34f0f
apply @pawelru feedback
m7pr Nov 19, 2024
2c0dbf0
fix: namespace change in server function applied to UI
averissimo Nov 19, 2024
ad54746
docs: test title
averissimo Nov 19, 2024
5b402e2
fix: reactivity issue
averissimo Nov 19, 2024
ffe1a19
docs: fix spelling
averissimo Nov 19, 2024
1ad0b84
Merge branch 'main' into 1187_decorate_output@main
averissimo Nov 20, 2024
f264ad1
Merge branch 'main' into 1187_decorate_output@main
m7pr Nov 20, 2024
20a3962
Update tests/testthat/test-teal_transform_module.R
m7pr Nov 20, 2024
0003fef
@averissimo suggestions on debounce removal
m7pr Nov 20, 2024
1b0d5fd
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 20, 2024
42035b7
Update decorators vignette for multiple decorators (#1418)
m7pr Nov 20, 2024
cc32fe0
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 20, 2024
e1e49da
fix superlintr
m7pr Nov 20, 2024
fbd34d8
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 20, 2024
113b0c7
feat: updates decorators argument on dummy
averissimo Nov 21, 2024
28c50a9
feat: add print statement to code
averissimo Nov 21, 2024
62913ae
fix: tests uses list of decorators
averissimo Nov 21, 2024
f493ee1
fix: corrects e2e tests and small fixes
averissimo Nov 21, 2024
fa298c8
docs: add decorators param
averissimo Nov 21, 2024
ed921de
chore: fix linter errors
averissimo Nov 21, 2024
26ceb2d
Update R/dummy_functions.R
averissimo Nov 21, 2024
452c9da
[skip style] [skip vbump] Restyle files
github-actions[bot] Nov 21, 2024
2078b1f
docs: fixes params documentation
averissimo Nov 21, 2024
4340c2b
chore: adds ggplot2 to suggests
averissimo Nov 21, 2024
8f42166
fix: update e2e test with newer examples code
averissimo Nov 21, 2024
ab8fe49
fix: examples
averissimo Nov 21, 2024
8cb4a52
fix: R CMD check note
averissimo Nov 21, 2024
e0b9e0e
fix: remove unnecessary div
averissimo Nov 22, 2024
a9a0b0e
chore: improve on error message
averissimo Nov 22, 2024
e7747c5
chore: improve on error message (missing on last commit)
averissimo Nov 22, 2024
a71e6d5
chore: use safer ids in transformators
averissimo Nov 22, 2024
be49c50
chore: minor rename of id
averissimo Nov 22, 2024
0f9565c
fix: show errors in transform even if there is no UI
averissimo Nov 22, 2024
f67584f
chore: rename ui/srv_teal_transform_data to ui/srv_transform_teal_data
averissimo Nov 22, 2024
6389232
fix: e2e test that had the old namespace
averissimo Nov 22, 2024
347b82a
fix: typo on documentation
averissimo Nov 22, 2024
0a15929
Fix examples on decorator vignette (#1423)
llrs-roche Nov 22, 2024
6c353fe
fix: reactivity on input
averissimo Nov 26, 2024
3a9c68f
example for multiple outputs
m7pr Nov 29, 2024
8992555
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
6cd9662
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
a91a1cf
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
2685527
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
e04a892
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
33749d8
Update vignettes/decorate-module-output.Rmd
m7pr Nov 29, 2024
be6fa32
Update vignettes/decorate-module-output.Rmd
averissimo Nov 29, 2024
51b0964
Update vignettes/decorate-module-output.Rmd
averissimo Nov 29, 2024
2fd5402
docs: vignette cleanup
averissimo Nov 29, 2024
93fe55c
Merge branch 'main' into 1187_decorate_output@main
averissimo Nov 29, 2024
e2f58e9
pr feedback: simplify
averissimo Nov 29, 2024
e5acbdc
chore: add formatters to lookup references
averissimo Nov 29, 2024
c36e7b9
chore: minor clean of vignette
averissimo Nov 29, 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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export(get_code_tdata)
export(get_metadata)
export(init)
export(landing_popup_module)
export(make_teal_transform_server)
export(module)
export(modules)
export(new_tdata)
Expand All @@ -30,12 +31,14 @@ export(reporter_previewer_module)
export(set_datanames)
export(show_rcode_modal)
export(srv_teal)
export(srv_teal_transform_module)
export(srv_teal_with_splash)
export(tdata2env)
export(teal_data_module)
export(teal_slices)
export(teal_transform_module)
export(ui_teal)
export(ui_teal_transform_module)
export(ui_teal_with_splash)
export(validate_has_data)
export(validate_has_elements)
Expand Down
24 changes: 8 additions & 16 deletions R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
args <- c(list(id = ns("module")), modules$ui_args)

ui_teal <- tagList(
div(
id = ns("validate_datanames"),
ui_validate_reactive_teal_data(ns("validate_datanames"))
),
shinyjs::hidden(
tags$div(
id = ns("transformer_failure_info"),
Expand All @@ -108,6 +104,10 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
),
tags$div(
id = ns("teal_module_ui"),
tags$div(
class = "teal_validated",
ui_check_module_datanames(ns("validate_datanames"))
),
do.call(modules$ui, args)
)
)
Expand All @@ -126,19 +126,13 @@ ui_teal_module.teal_module <- function(id, modules, depth = 0L) {
ui_data_summary(ns("data_summary")),
ui_filter_data(ns("filter_panel")),
if (length(modules$transformers) > 0 && !isTRUE(attr(modules$transformers, "custom_ui"))) {
ui_transform_data(ns("data_transform"), transforms = modules$transformers, class = "well")
ui_teal_transform_module(ns("data_transform"), transforms = modules$transformers, class = "well")
},
class = "teal_secondary_col"
)
)
} else {
div(
div(
class = "teal_validated",
uiOutput(ns("data_input_error"))
),
ui_teal
)
ui_teal
}
)
)
Expand Down Expand Up @@ -262,7 +256,7 @@ srv_teal_module.teal_module <- function(id,
)

is_transformer_failed <- reactiveValues()
transformed_teal_data <- srv_transform_data(
transformed_teal_data <- srv_teal_transform_module(
m7pr marked this conversation as resolved.
Show resolved Hide resolved
"data_transform",
data = filtered_teal_data,
transforms = modules$transformers,
Expand All @@ -275,11 +269,9 @@ srv_teal_module.teal_module <- function(id,
observeEvent(any_transformer_failed(), {
if (isTRUE(any_transformer_failed())) {
shinyjs::hide("teal_module_ui")
shinyjs::hide("validate_datanames")
shinyjs::show("transformer_failure_info")
} else {
shinyjs::show("teal_module_ui")
shinyjs::show("validate_datanames")
shinyjs::hide("transformer_failure_info")
}
})
Expand All @@ -291,7 +283,7 @@ srv_teal_module.teal_module <- function(id,
.subset_teal_data(all_teal_data, module_datanames)
})

srv_validate_reactive_teal_data(
srv_check_module_datanames(
"validate_datanames",
data = module_teal_data,
modules = modules
Expand Down
26 changes: 18 additions & 8 deletions R/module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#' performed:
#' - data loading in [`module_init_data`]
#' - data filtering in [`module_filter_data`]
#' - data transformation in [`module_transform_data`]
#' - data transformation in [`module_teal_transform_module`]
#'
#' ## Fallback on failure
#'
Expand Down Expand Up @@ -187,12 +187,20 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
)

data_pulled <- srv_init_data("data", data = data)
data_validated <- srv_validate_reactive_teal_data(
"validate",
data = data_pulled,
modules = modules,
validate_shiny_silent_error = FALSE

validate_ui <- tags$div(
id = session$ns("validate_messages"),
class = "teal_validated",
ui_check_class_teal_data(session$ns("class_teal_data")),
ui_validate_error(session$ns("silent_error")),
ui_check_module_datanames(session$ns("datanames_warning"))
)
srv_check_class_teal_data("class_teal_data", data_pulled)
srv_validate_error("silent_error", data_pulled, validate_shiny_silent_error = FALSE)
srv_check_module_datanames("datanames_warning", data_pulled, modules)

data_validated <- .trigger_on_success(data_pulled)

data_rv <- reactive({
req(inherits(data_validated(), "teal_data"))
is_filter_ok <- check_filter_datanames(filter, ls(teal.code::get_env(data_validated())))
Expand Down Expand Up @@ -225,6 +233,8 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
})
}



if (inherits(data, "teal_data_module")) {
setBookmarkExclude(c("teal_modules-active_tab"))
shiny::insertTab(
Expand All @@ -236,7 +246,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
value = "teal_data_module",
tags$div(
ui_init_data(session$ns("data")),
ui_validate_reactive_teal_data(session$ns("validate"))
validate_ui
)
)
)
Expand All @@ -253,7 +263,7 @@ srv_teal <- function(id, data, modules, filter = teal_slices()) {
insertUI(
selector = sprintf("#%s", session$ns("tabpanel_wrapper")),
where = "beforeBegin",
ui = tags$div(ui_validate_reactive_teal_data(session$ns("validate")), tags$br())
ui = tags$div(validate_ui, tags$br())
)
}

Expand Down
8 changes: 4 additions & 4 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ui_validate_reactive_teal_data <- function(id) {
class = "teal_validated",
ui_validate_error(ns("silent_error")),
ui_check_class_teal_data(ns("class_teal_data")),
ui_check_shiny_warnings(ns("shiny_warnings"))
ui_check_module_datanames(ns("shiny_warnings"))
),
div(
class = "teal_validated",
Expand All @@ -129,7 +129,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
# there is an empty reactive cycle on `init` and `data_rv` has `shiny.silent.error` class
srv_validate_error("silent_error", data, validate_shiny_silent_error)
srv_check_class_teal_data("class_teal_data", data)
srv_check_shiny_warnings("shiny_warnings", data, modules)
srv_check_module_datanames("shiny_warnings", data, modules)
pawelru marked this conversation as resolved.
Show resolved Hide resolved
output$previous_failed <- renderUI({
if (hide_validation_error()) {
shinyjs::hide("validate_messages")
Expand Down Expand Up @@ -211,13 +211,13 @@ srv_check_class_teal_data <- function(id, data) {
}

#' @keywords internal
ui_check_shiny_warnings <- function(id) {
ui_check_module_datanames <- function(id) {
ns <- NS(id)
uiOutput(NS(id, "message"))
}

#' @keywords internal
srv_check_shiny_warnings <- function(id, data, modules) {
srv_check_module_datanames <- function(id, data, modules) {
checkmate::assert_string(id)
moduleServer(id, function(input, output, session) {
output$message <- renderUI({
Expand Down
107 changes: 83 additions & 24 deletions R/module_transform_data.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
#' Module to transform `reactive` `teal_data`
#'
#' Module calls multiple [`module_teal_data`] in sequence so that `reactive teal_data` output
#' Module calls [teal_transform_module()] in sequence so that `reactive teal_data` output
#' from one module is handed over to the following module's input.
#'
#' @inheritParams module_teal_data
#' @inheritParams teal_modules
#' @return `reactive` `teal_data`
#'
#'
#' @name module_transform_data
#' @keywords internal
#' @name module_teal_transform_module
NULL

#' @rdname module_transform_data
ui_transform_data <- function(id, transforms, class = "well") {
#' @export
#' @rdname module_teal_transform_module
ui_teal_transform_module <- function(id, transforms, class = "well") {
checkmate::assert_string(id)
checkmate::assert_list(transforms, "teal_transform_module", null.ok = TRUE)
ns <- NS(id)
if (length(transforms) == 0L) {
return(NULL)
}
if (inherits(transforms, "teal_transform_module")) {
transforms <- list(transforms)
}
checkmate::assert_list(transforms, "teal_transform_module")

labels <- lapply(transforms, function(x) attr(x, "label"))
ids <- get_unique_labels(labels)
averissimo marked this conversation as resolved.
Show resolved Hide resolved
names(transforms) <- ids

lapply(
names(transforms),
function(name) {
child_id <- NS(id)(name)
ns <- NS(child_id)
data_mod <- transforms[[name]]
wrapper_id <- ns(sprintf("wrapper_%s", name))
transform_wrapper_id <- ns(sprintf("wrapper_%s", name))

div( # todo: accordion?
# class .teal_validated changes the color of the boarder on error in ui_validate_reactive_teal_data
# For details see tealValidate.js file.
Expand All @@ -40,39 +49,89 @@ ui_transform_data <- function(id, transforms, class = "well") {
class = "remove pull-right fa fa-angle-down",
style = "cursor: pointer;",
title = "fold/expand transform panel",
onclick = sprintf("togglePanelItems(this, '%s', 'fa-angle-right', 'fa-angle-down');", wrapper_id)
onclick = sprintf("togglePanelItems(this, '%s', 'fa-angle-right', 'fa-angle-down');", transform_wrapper_id)
),
div(
id = wrapper_id,
ui_teal_data(id = ns(name), data_module = transforms[[name]]$ui)
tags$div(
id = transform_wrapper_id,
if (is.null(data_mod$ui)) {
return(NULL)
averissimo marked this conversation as resolved.
Show resolved Hide resolved
} else {
data_mod$ui(id = ns(name))
},
div(
id = ns("validate_messages"),
class = "teal_validated",
uiOutput(ns("error_wrapper"))
)
)
)
}
)
}

#' @rdname module_transform_data
srv_transform_data <- function(id, data, transforms, modules, is_transformer_failed = reactiveValues()) {
#' @export
#' @rdname module_teal_transform_module
srv_teal_transform_module <- function(id, data, transforms, modules = NULL, is_transformer_failed = reactiveValues()) {
checkmate::assert_string(id)
assert_reactive(data)
checkmate::assert_list(transforms, "teal_transform_module", null.ok = TRUE)
checkmate::assert_class(modules, "teal_module")
checkmate::assert_class(modules, "teal_module", null.ok = TRUE)
if (length(transforms) == 0L) {
return(data)
}
if (inherits(transforms, "teal_transform_module")) {
transforms <- list(transforms)
}
checkmate::assert_list(transforms, "teal_transform_module", null.ok = TRUE)
labels <- lapply(transforms, function(x) attr(x, "label"))
ids <- get_unique_labels(labels)
names(transforms) <- ids

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_teal_data_modules initializing.")
Reduce(
function(previous_result, name) {
srv_teal_data(
id = name,
data_module = function(id) transforms[[name]]$server(id, previous_result),
modules = modules,
is_transformer_failed = is_transformer_failed
)
function(data_previous, name) {
moduleServer(name, function(input, output, session) {
logger::log_debug("srv_teal_transform_module initializing for { name }.")
is_transformer_failed[[name]] <- FALSE
data_out <- transforms[[name]]$server(name, data = data_previous)
data_handled <- reactive(tryCatch(data_out(), error = function(e) e))
observeEvent(data_handled(), {
if (inherits(data_handled(), "teal_data")) {
is_transformer_failed[[name]] <- FALSE
} else {
is_transformer_failed[[name]] <- TRUE
}
})

is_previous_failed <- reactive({
idx_this <- which(names(is_transformer_failed) == name)
is_transformer_failed_list <- reactiveValuesToList(is_transformer_failed)
idx_failures <- which(unlist(is_transformer_failed_list))
any(idx_failures < idx_this)
})

srv_validate_error("silent_error", data_handled, validate_shiny_silent_error = FALSE)
srv_check_class_teal_data("class_teal_data", data_handled)
if (!is.null(modules)) {
srv_check_module_datanames("datanames_warning", data_handled, modules)
}

transform_wrapper_id <- sprintf("wrapper_%s", name)
output$error_wrapper <- renderUI({
if (is_previous_failed()) {
shinyjs::disable(transform_wrapper_id)
tags$div("One of previous transformers failed. Please fix and continue.", class = "teal-output-warning")
} else {
shinyjs::enable(transform_wrapper_id)
shiny::tagList(
ui_validate_error(session$ns("silent_error")),
ui_check_class_teal_data(session$ns("class_teal_data")),
ui_check_module_datanames(session$ns("datanames_warning"))
)
}
})

.trigger_on_success(data_handled)
})
},
x = names(transforms),
init = data
Expand Down
21 changes: 15 additions & 6 deletions R/modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ setOldClass("teal_modules")
#' @param server_args (named `list`) with additional arguments passed on to the server function.
#' @param ui_args (named `list`) with additional arguments passed on to the UI function.
#' @param x (`teal_module` or `teal_modules`) Object to format/print.
#' @param indent (`integer(1)`) Indention level; each nested element is indented one level more.
#' @param transformers (`list` of `teal_data_module`) that will be applied to transform the data.
#' @param transformers (`list` of `teal_transform_module`) that will be applied to transform module's data input.
m7pr marked this conversation as resolved.
Show resolved Hide resolved
#' Each transform module UI will appear in the `teal` application, unless the `custom_ui` attribute is set on the list.
#' If so, the module developer is responsible to display the UI in the module itself. `datanames` of the `transformers`
#' will be added to the `datanames`.
#'
#' When the transformation does not have sufficient input data, the resulting data will fallback
#' to the last successful transform or, in case there are none, to the filtered data.
#'
#' @param ...
#' - For `modules()`: (`teal_module` or `teal_modules`) Objects to wrap into a tab.
#' - For `format()` and `print()`: Arguments passed to other methods.
Expand Down Expand Up @@ -315,7 +313,12 @@ modules <- function(..., label = "root") {

#' @rdname teal_modules
#' @export
format.teal_module <- function(x, indent = 0, ...) {
format.teal_module <- function(x, ...) {
m7pr marked this conversation as resolved.
Show resolved Hide resolved
if (is.null(list(...)$indent)) {
indent <- 0L
} else {
indent <- list(...)$indent
}
paste0(paste(rep(" ", indent), collapse = ""), "+ ", x$label, "\n", collapse = "")
}

Expand All @@ -330,7 +333,13 @@ print.teal_module <- function(x, ...) {

#' @rdname teal_modules
#' @export
format.teal_modules <- function(x, indent = 0, ...) {
format.teal_modules <- function(x, ...) {
if (is.null(list(...)$indent)) {
indent <- 0L
} else {
indent <- list(...)$indent
}

paste(
c(
paste0(rep(" ", indent), "+ ", x$label, "\n"),
Expand Down
Loading
Loading