From 434ca51a45834d0caf794cdc4dba8c73fd59c69f Mon Sep 17 00:00:00 2001 From: pvictor Date: Wed, 21 Feb 2024 15:31:27 +0100 Subject: [PATCH] fix progress bar js error --- R/progressBars.R | 37 +++++++++++++++++++------------------ man/progress-bar.Rd | 4 ++++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/R/progressBars.R b/R/progressBars.R index faf06016..b695319a 100644 --- a/R/progressBars.R +++ b/R/progressBars.R @@ -114,25 +114,22 @@ progressBar <- function(id, title, HTML(" ") ) - if (commas) { - value_for_display <- format_display(value) - total_for_display <- format_display(total) - } else { - value_for_display <- value - total_for_display <- total - } + value_for_display <- format_display(value) + total_for_display <- format_display(total) if (!is.null(total)) { - total <- tagList( - tags$span( - class = "progress-number float-right float-end", - tags$b(value_for_display, id = paste0(id, "-value")), - "/", - tags$span(id = paste0(id, "-total"), total_for_display) - ), - tags$div(class = "clearfix") - ) + } + total <- tagList( + tags$span( + class = "progress-number pull-right float-end", + style = css(display = if (is.null(total)) "none"), + tags$b(value_for_display, id = paste0(id, "-value")), + "/", + tags$span(id = paste0(id, "-total"), total_for_display) + ), + tags$div(class = "clearfix") + ) tagPB <- tags$div( class = "progress-group", @@ -172,8 +169,10 @@ updateProgressBar <- function(session = getDefaultReactiveDomain(), status = NULL, range_value = NULL, commas = TRUE, + format_display = function(value) { + prettyNum(value, big.mark = ",", scientific = FALSE) + }, unit_mark = "%") { - message <- "update-progressBar-shinyWidgets" if (!is.null(range_value)) { percent <- rescale(x = value, from = range_value, to = c(0, 100)) } else { @@ -186,12 +185,14 @@ updateProgressBar <- function(session = getDefaultReactiveDomain(), id <- session$ns(id) } session$sendCustomMessage( - type = message, + type = "update-progressBar-shinyWidgets", message = list( id = id, value = value, percent = percent, total = if (is.null(total)) -1 else total, + value_display = format_display(value), + total_display = format_display(total), title = as.character(title), status = status, commas = commas, diff --git a/man/progress-bar.Rd b/man/progress-bar.Rd index ebd21f7c..e421ab8c 100644 --- a/man/progress-bar.Rd +++ b/man/progress-bar.Rd @@ -33,6 +33,10 @@ updateProgressBar( status = NULL, range_value = NULL, commas = TRUE, + format_display = function(value) { + prettyNum(value, big.mark = ",", scientific = + FALSE) + }, unit_mark = "\%" ) }