The embed_img() function adds images obtained from the web to a column within reactable. It should be placed within the cell argument in reactable::colDef.

## Usage

embed_img(
data,
height = 24,
width = 24,
horizontal_align = "center",
label = NULL,
label_position = "right"
)

## Arguments

data

Dataset containing URL's to images

height

A value given for the height of the image in px. Default height is 24px.

width

A value given for the width of the image in px. Default width is 24px.

horizontal_align

The horizontal alignment of the image within a cell. Options are "left", "right", or "center". Default is "center".

label

Optionally assign a label to the image from another column. Default is set to NULL or no label.

label_position

Position of label relative to image. Options are "right", "left", "below", or "above". Default is right.

## Value

a function that renders an image to a column containing a valid web link.

## Examples

## 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" ~
Species == "versicolor" ~
Species == "virginica" ~
TRUE ~ "NA"))

## Then use embed_img() to display images
reactable(data,
columns = list(
img = colDef(cell = embed_img())))
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator ## By default, images are given a size of 24px by 24px, ## but you can adjust the size using height and width: reactable(data, columns = list( img = colDef(cell = embed_img(height = 50, width = 45)))) #> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator

## Optionally assign a label to the image from another column
reactable(data,
columns = list(
img = colDef(cell = embed_img(data, label = "Species"))))
#> Error in x$width %||% settings$fig.width * settings\$dpi: non-numeric argument to binary operator