The cell_fill() function

Let’s use the exibble dataset to create a simple, two-column gt table (keeping only the num and currency columns). Styles are added with tab_style() in two separate calls (targeting different body cells with the cells_body() helper function). With the cell_fill() helper funciton we define cells with a "lightblue" background in one instance, and "gray85" in the other.

exibble |>
  dplyr::select(num, currency) |>
  gt() |>
  fmt_number(decimals = 1) |>
  tab_style(
    style = cell_fill(color = "lightblue"),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
    )
  ) |>
  tab_style(
    style = cell_fill(color = "gray85"),
    locations = cells_body(
      columns = currency,
      rows = currency < 100
    )
  )
num currency
0.1 50.0
2.2 17.9
33.3 1.4
444.4 65,100.0
5,550.0 1,325.8
NA 13.3
777,000.0 NA
8,880,000.0 0.4