Search code examples
rkableextra

Save save_kable() to png with white background instead of default gray


I just need to change the background color of the whole table to white. A reproducible example

kable(head(iris)) %>%
  kable_styling("striped", full_width = FALSE, htmltable_class = 'lightable-classic-2') %>%
  add_header_above(c("Measurements" = 4L, " " = 1L)) %>% 
  kable_paper() %>%
  save_kable(file = 'tableX.png') 

enter image description here

What've found/tried:

  • add_header_above() has a background argument but that only affects the header.
  • save_kable() has the bs_theme argument but I can't find what the options are.
  • some functions have the extra_css argument but can't find a function that affects the whole table.

Solution

  • You can find some examples of bs_theme at bootswatch.com For my example I used flatly.

    library(kableExtra)
    
    
    kable(head(iris)) %>%
      kable_styling("striped", full_width = FALSE, htmltable_class = 'lightable-classic-2') %>%
      add_header_above(c("Measurements" = 4L, " " = 1L)) %>% 
      kable_paper() %>%
      save_kable(file = 'tableX.png', bs_theme = "flatly")
    

    enter image description here