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

Rename teal_data_module.R functions #1430

Merged
merged 21 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d861556
Internal srv_teal_data change
llrs-roche Dec 13, 2024
810c385
Rename {ui,srv}_teal_data to {ui,srv}_teal_data_module.
llrs-roche Dec 16, 2024
874aaf1
rename on srv_validate_reactive_teal_data
llrs-roche Dec 16, 2024
78499d9
Update text message
llrs-roche Dec 16, 2024
3e0eea9
Fix test failures
llrs-roche Dec 16, 2024
49823e6
Merge branch '1323_renames_teal_data_modules@main' of https://github.…
llrs-roche Dec 16, 2024
6868ae2
Remove ui_teal_data and srv_teal_data in favor of ui_teal_data_module…
llrs-roche Dec 17, 2024
74c1537
[skip style] [skip vbump] Restyle files
github-actions[bot] Dec 17, 2024
9338f9b
Fix style
llrs-roche Dec 17, 2024
04a4802
Merge branch '1323_renames_teal_data_modules@main' of https://github.…
llrs-roche Dec 17, 2024
7009e89
Replace teal_data_r, teal_data_rv, and data_rv to data
llrs-roche Dec 18, 2024
637723c
[skip roxygen] [skip vbump] Roxygen Man Pages Auto Update
github-actions[bot] Dec 18, 2024
14fa40b
Document parameter changes
llrs-roche Dec 18, 2024
f1701ba
Merged origin/1323_renames_teal_data_modules@main into 1323_renames_t…
llrs-roche Dec 18, 2024
3e0e419
Replace two more argument
llrs-roche Dec 18, 2024
4d00e74
Remove indentation of parameters
llrs-roche Dec 18, 2024
646eaca
Remove comment
llrs-roche Dec 18, 2024
ba31b42
Replace reactive check for the internal function
llrs-roche Dec 18, 2024
3e38b10
Avoid name conflict
llrs-roche Dec 18, 2024
ed97041
Adopt latest feedback
llrs-roche Dec 18, 2024
9d2e771
Merge branch 'main' into 1323_renames_teal_data_modules@main
m7pr Dec 18, 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
2 changes: 1 addition & 1 deletion R/dummy_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ example_module <- function(label = "example teal module",

table_data_decorated_no_print <- srv_transform_teal_data(
"decorate",
data = table_data,
teal_data_r = table_data,
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
transformators = decorators
)
table_data_decorated <- reactive(within(req(table_data_decorated_no_print()), expr = object))
Expand Down
2 changes: 1 addition & 1 deletion R/module_nested_tabs.R
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ srv_teal_module.teal_module <- function(id,
is_transform_failed <- reactiveValues()
transformed_teal_data <- srv_transform_teal_data(
"data_transform",
data = filtered_teal_data,
teal_data_r = filtered_teal_data,
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
transformators = modules$transformators,
modules = modules,
is_transform_failed = is_transform_failed
Expand Down
42 changes: 24 additions & 18 deletions R/module_teal_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' (except error 1).
#'
#' @param id (`character(1)`) Module id
#' @param data (`reactive teal_data`)
#' @param teal_data_r (`reactive teal_data`)
#' @param data_module (`teal_data_module`)
#' @param modules (`teal_modules` or `teal_module`) For `datanames` validation purpose
#' @param validate_shiny_silent_error (`logical`) If `TRUE`, then `shiny.silent.error` is validated and
Expand All @@ -37,7 +37,10 @@
NULL

#' @rdname module_teal_data
ui_teal_data <- function(id, data_module = function(id) NULL) {
#' @aliases ui_teal_data
#' @note
#' `ui_teal_data_module` was renamed from `ui_teal_data`.
ui_teal_data_module <- function(id, data_module = function(id) NULL) {
llrs-roche marked this conversation as resolved.
Show resolved Hide resolved
checkmate::assert_string(id)
checkmate::assert_function(data_module, args = "id")
ns <- NS(id)
Expand All @@ -49,23 +52,26 @@ ui_teal_data <- function(id, data_module = function(id) NULL) {
}

#' @rdname module_teal_data
srv_teal_data <- function(id,
data_module = function(id) NULL,
modules = NULL,
validate_shiny_silent_error = TRUE,
is_transform_failed = reactiveValues()) {
#' @aliases srv_teal_data
#' @note
#' `srv_teal_data_module` was renamed from `srv_teal_data`.
srv_teal_data_module <- function(id,
data_module = function(id) NULL,
modules = NULL,
validate_shiny_silent_error = TRUE,
is_transform_failed = reactiveValues()) {
checkmate::assert_string(id)
checkmate::assert_function(data_module, args = "id")
checkmate::assert_multi_class(modules, c("teal_modules", "teal_module"), null.ok = TRUE)
checkmate::assert_class(is_transform_failed, "reactivevalues")

moduleServer(id, function(input, output, session) {
logger::log_debug("srv_teal_data initializing.")
logger::log_debug("srv_teal_data_module initializing.")
is_transform_failed[[id]] <- FALSE
data_out <- data_module(id = "data")
data_handled <- reactive(tryCatch(data_out(), error = function(e) e))
observeEvent(data_handled(), {
if (!inherits(data_handled(), "teal_data")) {
module_out <- data_module(id = "data")
try_module_out <- reactive(tryCatch(module_out(), error = function(e) e))
observeEvent(try_module_out(), {
if (!inherits(try_module_out(), "teal_data")) {
is_transform_failed[[id]] <- TRUE
} else {
is_transform_failed[[id]] <- FALSE
Expand All @@ -89,7 +95,7 @@ srv_teal_data <- function(id,

srv_validate_reactive_teal_data(
"validate",
data = data_handled,
teal_data_r = try_module_out,
modules = modules,
validate_shiny_silent_error = validate_shiny_silent_error,
hide_validation_error = is_previous_failed
Expand Down Expand Up @@ -117,7 +123,7 @@ ui_validate_reactive_teal_data <- function(id) {

#' @rdname module_teal_data
srv_validate_reactive_teal_data <- function(id, # nolint: object_length
data,
teal_data_r,
modules = NULL,
validate_shiny_silent_error = FALSE,
hide_validation_error = reactive(FALSE)) {
Expand All @@ -127,9 +133,9 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length

moduleServer(id, function(input, output, session) {
# 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_module_datanames("shiny_warnings", data, modules)
srv_validate_error("silent_error", teal_data_r, validate_shiny_silent_error)
srv_check_class_teal_data("class_teal_data", teal_data_r)
srv_check_module_datanames("shiny_warnings", teal_data_r, modules)
output$previous_failed <- renderUI({
if (hide_validation_error()) {
shinyjs::hide("validate_messages")
Expand All @@ -140,7 +146,7 @@ srv_validate_reactive_teal_data <- function(id, # nolint: object_length
}
})

.trigger_on_success(data)
.trigger_on_success(teal_data_r)
})
}

Expand Down
12 changes: 8 additions & 4 deletions R/module_transform_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@ ui_transform_teal_data <- function(id, transformators, class = "well") {

#' @export
#' @rdname module_transform_data
srv_transform_teal_data <- function(id, data, transformators, modules = NULL, is_transform_failed = reactiveValues()) {
srv_transform_teal_data <- function(id,
teal_data_r,
transformators,
modules = NULL,
is_transform_failed = reactiveValues()) {
checkmate::assert_string(id)
assert_reactive(data)
assert_reactive(teal_data_r)
checkmate::assert_class(modules, "teal_module", null.ok = TRUE)
if (length(transformators) == 0L) {
return(data)
return(teal_data_r)
}
if (inherits(transformators, "teal_transform_module")) {
transformators <- list(transformators)
Expand Down Expand Up @@ -142,7 +146,7 @@ srv_transform_teal_data <- function(id, data, transformators, modules = NULL, is
})
},
x = names(transformators),
init = data
init = teal_data_r
)
module_output
})
Expand Down
15 changes: 11 additions & 4 deletions man/module_teal_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/module_transform_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/testthat/test-teal_transform_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ testthat::describe("make_teal_transform_server produces a valid teal_transform_m
app = srv_transform_teal_data,
args = list(
id = "test",
data = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
teal_data_r = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
transformators = output_decorator
),
expr = {
Expand All @@ -35,7 +35,7 @@ testthat::describe("make_teal_transform_server produces a valid teal_transform_m
app = srv_transform_teal_data,
args = list(
id = "test",
data = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
teal_data_r = reactive(teal.data::teal_data(data1 = iris, data2 = mtcars)),
transformators = output_decorator
),
expr = {
Expand Down Expand Up @@ -68,7 +68,7 @@ testthat::test_that(
app = srv_transform_teal_data,
args = list(
id = initial_id,
data = reactive(within(teal_data(), iris <- iris)),
teal_data_r = reactive(within(teal_data(), iris <- iris)),
transformators = ttm
),
expr = {
Expand Down
Loading