holtzy / quarto-tricks

A set of tips and tricks for Quarto
https://www.productive-r-workflow.com/quarto-tricks
50 stars 1 forks source link

`htmlwidget` object as lightbox class graphs in Quarto document #7

Open arodionoff opened 2 months ago

arodionoff commented 2 months ago

Question

Dear Yan,

Is it possible to show objects created by ggiraph (or other htmlwidget object) as lightbox class graphs in Quarto documents *.qmd, which can be clicked to open up into a pop-up window as interactive objects?

---
title: "ggiraph with Lightbox"
format:
  html:
    lightbox: true
---

```{r}
# add interactive points to a ggplot -------
library(ggplot2)
library(ggiraph)

dataset <- structure(list(qsec = c(16.46, 17.02, 18.61, 19.44, 17.02, 20.22
), disp = c(160, 160, 108, 258, 360, 225), carname = c("Mazda RX4",
"Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive", "Hornet Sportabout",
"Valiant"), wt = c(2.62, 2.875, 2.32, 3.215, 3.44, 3.46)), row.names = c("Mazda RX4",
"Mazda RX4 Wag", "Datsun 710", "Hornet 4 Drive", "Hornet Sportabout",
"Valiant"), class = "data.frame")
dataset

# plots
gg_point = ggplot(data = dataset) +
    geom_point_interactive(aes(x = wt, y = qsec, color = disp,
    tooltip = carname, data_id = carname)) + theme_minimal()

girafe(ggobj = gg_point)
holtzy commented 2 months ago

Good question! I'm not sure it will work.

However, check the "modal-graph" section of my tips and tricks:

https://www.productive-r-workflow.com/quarto-tricks

I think it is going to solve your need?

arodionoff commented 2 months ago

It works separately, but does not show interactive information on labels when expanded to full screen.

However, when embedded in the main document, the expanded interactive graph becomes gray and does not close at all. Even pressing the {ESC} key does not help.