'Combined Formattable with KableExtra

I am trying to create a table that combines features from Formattable with KableExtra. I have found a number of examples which have helped but doesn't quite do everything I'm trying to achieve.

This is what I've tried so far:

library(KableExtra)
library(Formattable)
df <- structure(list(Income_source = 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)), row.names = c(NA, 
                                                                       -4L), class = c("tbl_df", "tbl", "data.frame"))

enter image description here

Example of the Formattable function I'd like to apply. Note the color_tile is applied specifically to each row

formattable(df, lapply(1:nrow(df), function(row) {
  area(row, col = 1:nrow(df)) ~ color_tile("transparent", "pink")
}))

enter image description here

The example I found which lets me combine Formattable with KableExtra looks like this:

df %>% 
  mutate(Jul = formattable::color_tile("transparent", "pink")(Jul),
         Aug = formattable::color_tile("transparent", "pink")(Aug),
         Sep = formattable::color_tile("transparent", "pink")(Sep)) %>% 
  select(Name,everything()) %>% 
  kable("html", escape = F,format.args = list(big.mark = ",",scientific = FALSE)) %>%
  kable_classic(full_width = T, html_font = "Cambria") %>% 
  kable_styling(bootstrap_options = c("striped", "hover", "condensed", "responsive")) %>% 
  row_spec(0, bold = T)

enter image description here

The problems with this solution is:

1: The color_tile function is applied to columns rather than rows
2: The numeric values drop the commas

The table I'm planning on generating would be updated monthly so that next month the data for October would be presented, followed by November and so forth. As such I'm hoping for a solution that doesn't require me to edit the script each time i.e. mutate the new data. Hopefully that makes sense.

List item



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source