Skip to content

Commit

Permalink
feat: add decorator wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
averissimo committed Nov 25, 2024
1 parent ac879e7 commit 7c29d47
Show file tree
Hide file tree
Showing 39 changed files with 145 additions and 76 deletions.
32 changes: 32 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,35 @@ set_default_total_label <- function(total_label) {

# for mocking in tests
interactive <- NULL

#' Wrappers around `srv_transform_teal_data` that allows to decorate the data
#' @inheritParams teal::srv_transform_teal_data
#' @param expr (`expression`) to evaluate on the output of the decoration.
#' Must be inline code. See [within()]
#' Default is `NULL` which won't append any expression.
#' @details
#' `srv_decorate_teal_data` is a wrapper around `srv_transform_teal_data` that
#' allows to decorate the data with additional reactive expressions.
#' When original `teal_data` object is in error state, it will show that error
#' first.
#'
#' @keywords internal
srv_decorate_teal_data <- function(id, data, decorators, expr = NULL) {
expr_quosure <- rlang::enexpr(expr)
decorated_output <- srv_transform_teal_data(id, data = data, transformators = decorators)

reactive({
req(data(), decorated_output()) # ensure original errors are displayed
if (is.null(expr_quosure)) {
decorated_output()
} else {
eval_code(decorated_output(), expr_quosure)
}
})
}

#' @rdname srv_decorate_teal_data
#' @details
#' `ui_decorate_teal_data` is a wrapper around `ui_transform_teal_data`.
#' @keywords internal
ui_decorate_teal_data <- teal::ui_transform_teal_data
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ programmatically
repo
responder
responders
transformator
unadjusted
univariable
unstratified
36 changes: 36 additions & 0 deletions man/srv_decorate_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/tm_a_gee.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/tm_a_mmrm.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/tm_g_barchart_simple.Rd

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

Loading

0 comments on commit 7c29d47

Please sign in to comment.