I'm trying to add web images cropped using {cropcircle} to a reactable table. I've found the method for adding images straight from the web, and an example to graph the edited images with ggplot, but nothing for embedding them in a table. Any help would be greatly appreciated!
Needed libraries
library(ggplot2)
library(dplyr)
library(cropcircles)
library(tibble)
library(magick)
library(ggimage)
library(reactable)
Loading images & creating dataframe
images <- c(
"https://openpsychometrics.org/tests/characters/test-resources/pics/BB/1.jpg",
"https://openpsychometrics.org/tests/characters/test-resources/pics/BB/3.jpg",
"https://openpsychometrics.org/tests/characters/test-resources/pics/BB/9.jpg",
"https://openpsychometrics.org/tests/characters/test-resources/pics/BB/8.jpg")
df <- tibble(y = 1:4, images = images) |>
mutate(images_cropped = circle_crop(images)) # where the magic happens
Graphing Images works
df |>
ggplot() +
geom_image(aes(1.5, y, image = images), size = 0.15) +
geom_image(aes(3.5, y, image = images_cropped), size = 0.15) +
xlim(0, 5) +
ylim(0, 5) +
coord_fixed()
Attempt at making table renders web images only
df %>%
reactable(.,
theme = fivethirtyeight(centered = TRUE, header_font_size = 11),
columns = list(
images = colDef(
name = "",
maxWidth = 50,
sortable = FALSE,
# render team logos from their image address and increase their size
style = background_img(height = "200%", width = "125%"))))
Attempt at adding cropped images = error message
df %>%
reactable(.,
theme = fivethirtyeight(centered = TRUE, header_font_size = 11),
columns = list(
images = colDef(
name = "",
maxWidth = 50,
sortable = FALSE,
# render team logos from their image address and increase their size
style = background_img(height = "200%", width = "125%")),
images_cropped = colDef(
name = "",
maxWidth = 50,
sortable = FALSE,
style = background_img())))