# NOT RUN {
library(dplyr)
## Default sparkline bar chart
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkbar(.))))
## Highlight particular bars
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkbar(.,
decimals = 1,
min_value = 0,
highlight_bars = highlight_bars(min="red",max="blue")))))
## Conditionally assign fill colors to groups
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
mutate(flower_cols = case_when(
Species == "setosa" ~ "purple",
Species == "versicolor" ~ "darkgreen",
Species == "virginica" ~ "orange",
TRUE ~ "grey"
)) %>%
reactable(.,
columns = list(flower_cols = colDef(show=FALSE),
sepal_length = colDef(cell = react_sparkbar(.,
height = 80,
fill_color_ref = "flower_cols"))))
## Add labels to particular bars
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkbar(.,
height = 80,
decimals = 1,
highlight_bars = highlight_bars(first="blue",last="red"),
labels = c("first","last")))))
## Add statline to show the mean for each sparkbar
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkbar(.,
height = 80,
decimals = 1,
statline = "mean"))))
## Combine multiple elements together
iris %>%
group_by(Species) %>%
summarize(sepal_length = list(Sepal.Length)) %>%
reactable(.,
columns = list(sepal_length = colDef(cell = react_sparkbar(.,
height = 80,
decimals = 1,
statline = "mean",
bandline = "innerquartiles"))))
# }
Run the code above in your browser using DataLab