diff --git a/NEWS.md b/NEWS.md index 85e2452f..75217aa6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/verbatim_popup.R b/R/verbatim_popup.R index c78d943b..00b8c4e1 100644 --- a/R/verbatim_popup.R +++ b/R/verbatim_popup.R @@ -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")) ) } @@ -44,8 +44,8 @@ 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) @@ -53,7 +53,12 @@ verbatim_popup_srv <- function(id, verbatim_content, title, style = FALSE, disab 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), @@ -82,7 +87,8 @@ disabled_flag_observer <- function(disabled_flag, button_id) { } else { shinyjs::enable(button_id) } - } + }, + ignoreInit = ignoreInit ) } diff --git a/man/verbatim_popup.Rd b/man/verbatim_popup.Rd index 45ecc7b4..b92fd2c0 100644 --- a/man/verbatim_popup.Rd +++ b/man/verbatim_popup.Rd @@ -32,7 +32,8 @@ holding any of the above) the content to show in the popup modal window} If \code{verbatim_content} is a \code{condition} or \code{reactive} holding \code{condition} then this argument is ignored} \item{disabled}{(\code{reactive(1)}) the \code{shiny} reactive value holding a \code{logical}. The popup button is disabled -when the flag is \code{TRUE} and enabled otherwise} +when the flag is \code{TRUE} and enabled otherwise. +In order for this to be used you need to have \code{shinyjs::useShinyjs()} in the \code{UI} of your application.} } \value{ the UI function returns a \code{shiny.tag.list} object