# NOT RUN {
## If no image links are in the original dataset, you need to assign them like so:
library(dplyr)
data <- iris %>%
mutate(
img = case_when(
Species == "setosa" ~
"https://upload.wikimedia.org/wikipedia/commons/d/d9/Wild_iris_flower_iris_setosa.jpg",
Species == "versicolor" ~
"https://upload.wikimedia.org/wikipedia/commons/7/7a/Iris_versicolor.jpg",
Species == "virginica" ~
"https://upload.wikimedia.org/wikipedia/commons/9/9f/Iris_virginica.jpg",
TRUE ~ "NA"))
reactable(data,
columns = list(
img = colDef(style = background_img())))
## By default, images are given a size of 100% to fill the entire cell,
## but you can adjust the size using height and width:
reactable(data,
columns = list(
img = colDef(style = background_img(height = "50%", width = "50%"))))
## An image can be applied directly over an existing column using img:
reactable(data,
columns = list(
Species = colDef(
style = background_img(
img = "https://upload.wikimedia.org/wikipedia/commons/2/26/Colored_flowers_e.jpg"))))
## Conditionally assigned images can be applied directly over an existing column using img_ref:
reactable(data,
columns = list(
Species = colDef(style = background_img(data, img_ref = "img"))))
# }
Run the code above in your browser using DataLab