Given a data frame with a column of links to images (<img src...>
), is it possible to use reactable
's expandable row feature to expand a row and view an image?
Here is some basic data:
library(tidyverse)
library(reachable)
img_df <- tribble(~image,
"<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/5/56/Kosaciec_szczecinkowaty_Iris_setosa.jpg/450px-Kosaciec_szczecinkowaty_Iris_setosa.jpg'/>",
"<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Iris_versicolor_3.jpg/320px-Iris_versicolor_3.jpg'/>",
"<img src='https://upload.wikimedia.org/wikipedia/commons/thumb/9/9f/Iris_virginica.jpg/295px-Iris_virginica.jpg'/>"
)
iris %>%
group_by(Species) %>%
summarize(mean = mean(Sepal.Length)) %>%
add_column(img_df) -> df
reactable(df)
So, rather than show the "image" column, it would appear as an expandable column with the image appearing when the row is expanded.
I can get the HTML to appear with this code, but the image itself does not:
reactable(df,
columns = list(
image = colDef(html = TRUE,
resizable = TRUE,
show=F)
),
details = function(index) {
if(df$image[index] != "") {
htmltools::HTML(df$image[index])
}
})
I can get the image appear with this code, but it comes with all the additional row info. (This was taken from the documentation [https://glin.github.io/reactable/articles/examples.html#expandable-row-details-1]
reactable(df, details = colDef(
name = "More",
details = JS("function(rowInfo) {
return 'Details for row: ' + rowInfo.index +
'<pre>' + JSON.stringify(rowInfo.row, null, 3) + '</pre>'
}"),
html = TRUE,
width = 60
))