Editing Kable Table

Sorry to take so long getting bark to you but I was not having any more luck with kableExtra.

If you are not committed to {kableExtra} then I may have a solution for you with {flextable}. I think I found a couple of bugs but if you can function with just the table inserted into a document such as RMarkdown or even Word, I think this will work.

My possible bugs. flextime output is strange and is stripping caption.

Table1 <-  read.csv("raw.data.csv") 

# names changed for my convenience
names(Table1) <- c("district", "last", "last7", "last14", "rate")

set_flextable_defaults(
  font.family = "Arial", font.size = 10, 
  border.color = "black")


tb1 <- flextable(Table1) |> 
  bold(part = "header") |> 
      color(~ rate  < 0, color = "green", ~ rate) |> 
       color(~ rate  >= 0, color = "red", ~ rate) 
            


tb1 <- set_header_labels(
  x = tb1,
  values = c(
    district = "District",
    last = "Date of Last Case",
    last7 = "Cases in last 7 days",
    last14 = "Cases in last 14 days",
    rate = "% Change"
  )
)

set_table_properties(tb1, width = .5, layout = "autofit")

save_as_image(tb1, "tb1.png")