How to put currency prefix (R$) in the status bar of R's shinyWidgets package?

Question:

Is there any way to show the numbers as currency (R$), including thousands and cents separator, in the progress bars of shinyWidgets' shiny package? I'm trying to run some code, but they all convert numbers to strings, so shiny can't calculate.

In the example, I would like it to look like this:

BRL 1,000,000.70 / BRL 5,000,000.29

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
        progressBar(id = "pb1", value = 1000000.70, 
                    total = 5000000.29, status = "info", display_pct = TRUE, striped = TRUE, 
                    title = "DONATION"),

        progressBar(id = "pb2", value = as.numeric(1000000.70, options(scipen=999)), 
                    total = as.numeric(5000000.29, options(scipen=999), status = "info", display_pct = TRUE, striped = TRUE, 
                    title = "DONATION")
)
)
server <- function(input, output) {}

shinyApp(ui = ui, server = server)

Answer:

You can use the dollar_format function from the scales package, looking like this:

library(scales)

real <- dollar_format(prefix = "R$ ")

Just use the function with any value inside that will return with the prefix "R$". Ex.:

real(10)

#> [1] "R$ 10"
Scroll to Top