Skip to contents

Apply styles to a column according to CSS properties declared by expression based on data passed to grid..

Usage

grid_style_column(
  grid,
  column,
  background = NULL,
  color = NULL,
  fontWeight = NULL,
  ...
)

Arguments

grid

A grid created with datagrid().

column

Name of column (variable name) where to apply style.

background

Background color.

color

Text color.

fontWeight

Font weight, you can use "bold" for example.

...

Other CSS properties.

Value

A datagrid htmlwidget.

Examples


library(toastui)
library(scales)

datagrid(mtcars) %>%
  grid_style_column(
    column = "mpg",
    background = col_numeric("Blues", domain = NULL)(mpg),
    fontWeight = "bold",
    color = ifelse(mpg > 25, "white", "black")
  )
mpgcyldisphpdratwtqsecvsamgearcarb
21
6
160
110
3.9
2.62
16.46
0
1
4
4
21
6
160
110
3.9
2.875
17.02
0
1
4
4
22.8
4
108
93
3.85
2.32
18.61
1
1
4
1
21.4
6
258
110
3.08
3.215
19.44
1
0
3
1
18.7
8
360
175
3.15
3.44
17.02
0
0
3
2
18.1
6
225
105
2.76
3.46
20.22
1
0
3
1
14.3
8
360
245
3.21
3.57
15.84
0
0
3
4
24.4
4
146.7
62
3.69
3.19
20
1
0
4
2
22.8
4
140.8
95
3.92
3.15
22.9
1
0
4
2
19.2
6
167.6
123
3.92
3.44
18.3
1
0
4
4
datagrid(mtcars) %>% grid_style_column( column = "mpg", background = col_numeric("Blues", domain = NULL)(mpg), fontWeight = "bold", color = ifelse(mpg > 25, "white", "black") ) %>% grid_style_column( column = "cyl", background = col_bin("Blues", domain = NULL)(cyl), fontStyle = "italic" )
mpgcyldisphpdratwtqsecvsamgearcarb
21
6
160
110
3.9
2.62
16.46
0
1
4
4
21
6
160
110
3.9
2.875
17.02
0
1
4
4
22.8
4
108
93
3.85
2.32
18.61
1
1
4
1
21.4
6
258
110
3.08
3.215
19.44
1
0
3
1
18.7
8
360
175
3.15
3.44
17.02
0
0
3
2
18.1
6
225
105
2.76
3.46
20.22
1
0
3
1
14.3
8
360
245
3.21
3.57
15.84
0
0
3
4
24.4
4
146.7
62
3.69
3.19
20
1
0
4
2
22.8
4
140.8
95
3.92
3.15
22.9
1
0
4
2
19.2
6
167.6
123
3.92
3.44
18.3
1
0
4
4