How to add comma's to a datatable output?

Viewed 37

I would like to edit my datatable so that my numeric values contain commas.

My data looks like this

library(formattable)

 df <-  structure(list(Name = c("A", "B", "C", "C"), 
                       Jul = c(1777.01, 0.13, 9587.39, 11364.53),
                       Aug = c(0, 0.09, 9908.78, 9908.87),
                       Sep = c(5374.6, 0.03, 9859.87, 15234.5), 
                       Oct = c(2738.46,0.07, 11581.19, 14319.72), 
                       Nov = c(543.35, 0.04, 10351.97,10895.36), 
                       Dec = c(3544.69, 0.09, 15282.56, 18827.34), 
                       Jan = c(0,0.16, 10179.48, 10179.64)), 
                  row.names = c(NA, -4L), class = c("tbl_df","tbl", "data.frame"))

my datatable output like this

df %>%
    formattable(lapply(1:nrow(df), function(row) {
      area(row, col = -ncol(df)) ~ color_tile("transparent", "pink")})) %>% 
    as.datatable(escape = FALSE)

enter image description here

How do I edit my datatable so that the numbers contain commas i.e. 5,374.60 but the cells also retain the colour scheme?

0 Answers
Related