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

Handle reactivity for disabled in modules #98

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# teal.widgets 0.2.0.9000

### Breaking change
* Added `ignoreInit` argument to `verbatim_popup_srv`. By default this is set to `TRUE`. To use previous behavior set it to `FALSE`.

# teal.widgets 0.2.0

### Breaking changes
Expand Down
16 changes: 11 additions & 5 deletions R/verbatim_popup.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ verbatim_popup_ui <- function(id, button_label, ...) {
shiny::singleton(
shiny::tags$head(shiny::includeScript(system.file("js/verbatim_popup.js", package = "teal.widgets")))
),
shiny::actionButton(ns("button"), label = button_label, ...)
shiny::uiOutput(ns("container"))
)
}

Expand All @@ -44,16 +44,21 @@ verbatim_popup_ui <- function(id, button_label, ...) {
#' @param style (`logical(1)`) whether to style the `verbatim_content` using `styler::style_text`.
#' If `verbatim_content` is a `condition` or `reactive` holding `condition` then this argument is ignored
#' @param disabled (`reactive(1)`) the `shiny` reactive value holding a `logical`. The popup button is disabled
#' when the flag is `TRUE` and enabled otherwise
#'
#' when the flag is `TRUE` and enabled otherwise.
#' In order for this to be used you need to have `shinyjs::useShinyjs()` in the `UI` of your application.
verbatim_popup_srv <- function(id, verbatim_content, title, style = FALSE, disabled = shiny::reactiveVal(FALSE)) {
checkmate::assert_string(id)
checkmate::assert_string(title)
checkmate::assert_flag(style)
checkmate::assert_class(disabled, classes = "reactive")
moduleServer(id, function(input, output, session) {
ns <- session$ns
disabled_flag_observer(disabled, "button")

output$container <- renderUI({
disabled_flag_observer(disabled, "button")
shiny::actionButton(session$ns("button"), label = "my label")
})

modal_content <- format_content(verbatim_content, style)
button_click_observer(
click_event = shiny::reactive(input$button),
Expand Down Expand Up @@ -82,7 +87,8 @@ disabled_flag_observer <- function(disabled_flag, button_id) {
} else {
shinyjs::enable(button_id)
}
}
},
ignoreInit = ignoreInit
)
}

Expand Down
3 changes: 2 additions & 1 deletion man/verbatim_popup.Rd

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