Skip to content

Commit

Permalink
Use rlang::enquo to preserve callback
Browse files Browse the repository at this point in the history
The callback had been being consumed, preventing repeat evaluation.

Using `rlang::enquo` casts `callback` to a quosure on button initialisation which can be repeatedly evaluated.
  • Loading branch information
grddavies committed Nov 5, 2021
1 parent e214f34 commit ee36cb5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Imports:
config (>= 0.3.1),
golem (>= 0.3.1),
purrr,
rlang,
shiny (>= 1.6.0)
Encoding: UTF-8
LazyData: true
Expand Down
5 changes: 3 additions & 2 deletions R/mod_calc_button.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ mod_calc_button_ui <- function(id) {
)
}

#' calc_button Server Functions
#' calc_button Server Function
#'
#' @noRd
mod_calc_button_server <- function(id, buttonType, callback) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
callback <- rlang::enquo(callback)
output$btnUI <- renderUI(actionButton(ns("btn"), buttonType))
observeEvent(input$btn, {
eval.parent(callback)
rlang::eval_tidy(callback)
})
})
}

0 comments on commit ee36cb5

Please sign in to comment.