Skip to content

Apply same style rule to several columns where row expression is effectively the same #1088

Answered by rich-iannone
arthur-shaw asked this question in Q&A
Discussion options

You must be logged in to vote

As of v0.8.0 of gt, we can now use tab_style_body() to make this a bit easier. Here's the updated code:

library(gt)
library(tidyverse)

df <- tibble::tribble(
  ~a, ~b, ~c,
  1, 2, 10,
  10, 10, 1,
  5, 1, 2
)

my_style <- list(
  gt::cell_fill(color = "#F9E3D6"),
  gt::cell_text(style = "italic")
)

df |>
  gt::gt() |>
  tab_style_body(fn = function(x) x >=5, style = my_style)

For now, we have to use fn = function(x) x >=5 but I'm hoping to improve it later so it accepts fn = ~ x >=5.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by arthur-shaw
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants