I have a tibble in R with nested rows and I created a ggplot
object per row. I would like to print these graphics using reactable
's expandable rows feature.
I think an example will explain this best. I'll use iris
for simplicity. First, we take iris
, nest it by "Species", and then make a column called "plot" that contains ggplot objects:
library(dplyr)
library(reactable)
library(ggplot2)
df = iris %>%
as_tibble() %>%
nest_by(Species) %>%
mutate(plot = list(
ggplot(data, aes(x=Sepal.Length, y=Sepal.Width)) + geom_point() + ggtitle(Species)
))
It is possible to make a reactable object on our dataframe that spits out a nested reactable when you click on any row:
reactable(df %>% select(Species), details = function(index) {
reactable(df$data[[index]])
}
)
BUT...I can't figure out how to do the equivalent thing for printing the "plot" column. For example, this doesn't work:
reactable(df %>% select(Species), details = function(index) {
print(df$plot[[index]])
}
)
I've poked around with some HTML things like htmltools::img(df$plot[[index]])
but it's all not working.
Any thoughts?? Thanks!!!!!