The tab_style() function

Use exibble to create a gt table. Add styles that are to be applied to data cells that satisfy a condition (using tab_style()).

exibble |>
  dplyr::select(num, currency) |>
  gt() |>
  fmt_number(
    columns = c(num, currency),
    decimals = 1
  ) |>
  tab_style(
    style = list(
      cell_fill(color = "lightcyan"),
      cell_text(weight = "bold")
      ),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
    )
  ) |>
  tab_style(
    style = list(
      cell_fill(color = "#F9E3D6"),
      cell_text(style = "italic")
      ),
    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

Use sp500 to create a gt table. Color entire rows of cells based on values in a particular column.

sp500 |>
  dplyr::filter(
    date >= "2015-12-01" &
    date <= "2015-12-15"
  ) |>
  dplyr::select(-c(adj_close, volume)) |>
  gt() |>
  tab_style(
    style = cell_fill(color = "lightgreen"),
    locations = cells_body(rows = close > open)
  ) |>
  tab_style(
    style = list(
      cell_fill(color = "red"),
      cell_text(color = "white")
      ),
    locations = cells_body(rows = open > close)
  )
date open high low close
2015-12-15 2025.55 2053.87 2025.55 2043.41
2015-12-14 2013.37 2022.92 1993.26 2021.94
2015-12-11 2047.27 2047.27 2008.80 2012.37
2015-12-10 2047.93 2067.65 2045.67 2052.23
2015-12-09 2061.17 2080.33 2036.53 2047.62
2015-12-08 2073.39 2073.85 2052.32 2063.59
2015-12-07 2090.42 2090.42 2066.78 2077.07
2015-12-04 2051.24 2093.84 2051.24 2091.69
2015-12-03 2080.71 2085.00 2042.35 2049.62
2015-12-02 2101.71 2104.27 2077.11 2079.51
2015-12-01 2082.93 2103.37 2082.93 2102.63

Use exibble to create a gt table. Replace missing values with the sub_missing() function and then add styling to the char column with cell_fill() and with a CSS style declaration.

exibble |>
  dplyr::select(char, fctr) |>
  gt() |>
  sub_missing() |>
  tab_style(
    style = list(
      cell_fill(color = "lightcyan"),
      "font-variant: small-caps;"
    ),
    locations = cells_body(columns = char)
  )
char fctr
apricot one
banana two
coconut three
durian four
five
fig six
grapefruit seven
honeydew eight