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

Asked

Viewed 69 times

3

Is there any way to show the numbers as currency (R$), including thousands and cents separator, in the progress bars of Shiny’s shinyWidgets 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 stay so:

R$1,000,000,70/R$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)
  • I don’t usually use Shiny, but a paste0 along with the function format before the values would not solve?

  • 1

    Hello! The Paste (and paste0) function convert numeric entries into string. Thus, Shiny cannot calculate the ratio between the total value and the input and gives error. Thanks for the contribution, Alexandre.

1 answer

2

You can use the function dollar_format package scales, being as follows:

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"
  • 1

    Thank you very much for being with me trying to decipher this dilemma. rs

  • I hope I have helped, if you thought it useful this reply, please mark as "answer accepted" by clicking on the check. Thank you!

  • 1

    We are still in the same situation. Passing the value through the "dollar_format", it continues to transform the Numeric format object into a string. In this way, Shiny cannot calculate. Thank you very much for being with me trying to decipher this dilemma. rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.