3

I am using {reactable} along with colFormat feature to format a table to my needs.

However, for some columns, I need specifically space as thousand separator and dot as decimal separator.

Both thousand and decimal separators depend on the locales parameter defined in colFormat and the possible options for these locales are listed here. I've tried all of them, and none of them use a space as thousand separator and a dot as decimal separator.

Is there a workaround to achieve the format I want while still using reactable? (and not hard formatting my numeric column in characters)

kenshuri
  • 472
  • 3
  • 11

1 Answers1

1

I need specifically space as thousand separator and dot as decimal separator.

You may achieve the desired output with cell rendering.
Let's use one of Glin's examples and observe the column NEW:

data <- data.frame(
  USD = c(12.12, 2141.213, 0.42, 1.55, 34414),
  EUR = c(10.68, 1884.27, 0.37, 1.36, 30284.32),
  INR = c(861.07, 152122.48, 29.84, 110, 2444942.63),
  JPY = c(1280, 226144, 44.36, 164, 3634634.61),
  MAD = c(115.78, 20453.94, 4.01, 15, 328739.73),
  NEW = c(11115.78, 2045320453.94, 4.01, 15, 328739.73)
)

reactable(data, columns = list(
  USD = colDef(
    format = colFormat(currency = "USD", separators = TRUE, locales = "en-US")
  ),
  EUR = colDef(
    format = colFormat(currency = "EUR", separators = TRUE, locales = "de-DE")
  ),
  INR = colDef(
    format = colFormat(currency = "INR", separators = TRUE, locales = "hi-IN")
  ),
  JPY = colDef(
    format = colFormat(currency = "JPY", separators = TRUE, locales = "ja-JP")
  ),
  MAD = colDef(
    format = colFormat(currency = "MAD", separators = TRUE, locales = "ar-MA")
  ),
  NEW = colDef(
    cell = function(value) format(value, nsmall = 2, big.mark = " ")
    # cell = function(values) formatC(x = values, digits = 2, big.mark = " ", format = "f")
  )
))

Output: enter image description here

Is this what you have in mind?

Radovan Miletić
  • 2,521
  • 1
  • 7
  • 13