Apply same style rule to several columns where row expression is effectively the same #1088
-
Ultimately, I want to flag extreme values in a several table columns. Presently, I need write code that provides a style rule for each column where extreme values are to be detected. For example:
If the expression in If the expression in Is there a more compact way to target multiple columns with the same In effect, I would like to be able to write something like this, inspired by
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As of v0.8.0 of gt, we can now use 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 |
Beta Was this translation helpful? Give feedback.
-
Many thanks, @rich-iannone ! This is a fantastic addition. I've loved |
Beta Was this translation helpful? Give feedback.
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:For now, we have to use
fn = function(x) x >=5
but I'm hoping to improve it later so it acceptsfn = ~ x >=5
.