# NOT RUN {
# Use `exibble` to create a gt table;
# add styles that are to be applied
# to data cells that satisfy a
# condition (using `tab_style()`)
tab_1 <-
exibble %>%
dplyr::select(num, currency) %>%
gt() %>%
fmt_number(
columns = vars(num, currency),
decimals = 1
) %>%
tab_style(
style = list(
cell_fill(color = "lightcyan"),
cell_text(weight = "bold")
),
locations = cells_body(
columns = vars(num),
rows = num >= 5000)
) %>%
tab_style(
style = list(
cell_fill(color = "#F9E3D6"),
cell_text(style = "italic")
),
locations = cells_body(
columns = vars(currency),
rows = currency < 100)
)
# Use `sp500` to create a gt table;
# color entire rows of cells based
# on values in a particular column
tab_2 <-
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)
)
# }
Run the code above in your browser using DataLab