I'm trying to write a dashboard with shinydashboard in R to display some values using renderValueBox and valueBoxOutput. These values are not hardcoded but are being scraped from another source daily. These values are currency numbers and should be reporting like $XXX,XXX.XX but instead I see XXXXXX.XX. Is there a way, like a wrapper, to easily format those values? Otherwise I've thought of brute forcing some regex on it with gsub...but ew. Please and thanks :)
How to format currency values in valueBox shinydashboard?
3k views Asked by kay At
2
There are 2 answers
0
On
Another way is to use the {scales}
package and the dollar_format()
function.
This function is a labelling function factory, in the sense that it creates other functions.
I usually need to output numbers in euros, so I defined the following function:
euro_format <- scales::dollar_format(
prefix = "\u20ac", # the euro symbol
suffix = "",
big.mark = ",",
decimal.mark = ".",
accuracy = 1
)
>euro_format(20842)
[1] "€20,842"
Discovered the function
prettyNum()
: this function is amazing for simple conversion to comma separated numerics.