# NOT RUN {
library(magrittr)
## Create the reactable table and then pipe in the legend
data <- iris[10:29, ]
table <- reactable(data,
columns = list(Sepal.Length = colDef(
cell = color_tiles(data))))
table %>%
add_legend(data = data,
col_name = "Sepal.Length")
## The legend can be aligned to either the left or right side
table %>%
add_legend(data = data,
col_name = "Sepal.Length",
align = "left")
## Change the number of bins within the legend
table %>%
add_legend(data = data,
col_name = "Sepal.Length",
bins = 9)
## Add a title and footer to the legend
table %>%
add_legend(data = data,
col_name = "Sepal.Length",
title = "Sepal Length",
footer = "measured in cm")
## If custom colors are used in the table, you can assign those to the legend as well
table <- reactable(data,
columns = list(Sepal.Length = colDef(
style = color_scales(data, colors = c("red","white","blue")))))
table %>%
add_legend(data = data,
col_name = "Sepal.Length",
colors = c("red","white","blue"))
# }
Run the code above in your browser using DataLab