-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod_calc_button.R
36 lines (35 loc) · 930 Bytes
/
mod_calc_button.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' calc_button UI Function
#'
#' @description UI module to render calculator buttons.
#'
#' @param id the ID of the `mod_calc_button_server` to render
#'
#' @noRd
#'
#' @importFrom shiny NS tagList
mod_calc_button_ui <- function(id) {
ns <- NS(id)
tagList(
uiOutput(ns("btnUI"))
)
}
#' calc_button Server Function
#'
#' @description Server side logic for calculator buttons
#'
#' @param id the button id
#' @param label the label to render on the button
#' @param callback function to be evaluated on press
#' @param \dots additional arguments to `shiny::actionButton`
#'
#' @noRd
mod_calc_button_server <- function(id, label, callback, ...) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
callback <- rlang::enquo(callback)
output$btnUI <- renderUI(actionButton(ns("btn"), label, width = "50px", ...))
observeEvent(input$btn, {
rlang::eval_tidy(callback)
})
})
}