Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I enable the Quarto lightbox feature in gt tables that have images? #1670

Open
pedrotercero3 opened this issue May 19, 2024 · 1 comment

Comments

@pedrotercero3
Copy link

Hi all,

Quarto 1.4 has a lightbox feature that makes images clickable to see a larger version with a zoom animation. However, when adding images to a gt table (using the local_image() or ggplot_image() functions) the lightbox behavior does not apply to them. Is there a way to extend the lightbox functionality to does images too? Thanks!

Here is a minimal reprex with a Quarto document:
---
title: "gt lightbox test"
format: 
  html:
    lightbox: true
editor: visual
---

```{r}
library(tidyverse)
library(gt)
```

# This plot image works with lightbox

```{r}
plot_object <-
  ggplot(
    data = gtcars,
    aes(x = hp, y = trq, size = msrp)
  ) +
  geom_point(color = "blue") +
  theme(legend.position = "none")

plot_object
```

# The plot in this table doesn't work with lightbox

```{r}
dplyr::tibble(
  text = "Here is a ggplot:",
  ggplot = NA
) |>
  gt() |>
  text_transform(
    locations = cells_body(columns = ggplot),
    fn = function(x) {
      plot_object |>
        ggplot_image(height = px(200))
    }
  )
```
@matthewcurrier
Copy link

I've been trying to do something similar myself and managed to get this to work.

Try this...

dplyr::tibble(
  text = "Here is a ggplot:",
  ggplot = NA
) |>
  gt() |>
  text_transform(
    locations = cells_body(columns = ggplot),
    fn = function(x) {
      p <- plot_object |>
        ggplot_image(height = px(200))
      paste0('<a href="" class="lightbox" data-glightbox="title: Your title; description: description here; descPosition: left; type: image; effect: fade; width: 900px; height: auto; zoomable: true; draggable: true;">', p, '</a>')
    }
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants