-
Notifications
You must be signed in to change notification settings - Fork 338
Description
Overview
This issue is to lay out my thoughts about a gallery feature for pkgdown sites. The goal is to facilitate making pages similar to the existing learnr and flexdashboard examples pages.
The gallery I envision would require BS5 and would use Bootstrap's cards component. If a link is provided, the card image and title would be a clickable link.
Data Structure
At its core, the gallery would be created with a YAML list:
- title: "Setting Up R"
image: images/tutorial-ex-setup-r.png
link: https://learnr-examples.shinyapps.io/ex-setup-r/
footer: >
[Source](https://github.com/rstudio/learnr/tree/main/inst/tutorials/ex-setup-r/ex-setup-r.Rmd)
description: >
A tutorial featuring videos and interactive questions to guide a new **R** user
through the installation and set up of everything they'll need to get
started with **R**.API
The primary question I'm facing is how a user would instantiate a gallery. Here are a few options I've thought of, but I'd love to hear your thoughts on the user-facing API.
With an R function
One option would be to call a function exported by pkgdown, that would read the data from this file (or optionally would accept an R list):
```{r gallery, echo=FALSE}
pkgdown::gallery("examples.yml")
```The advantage is that this function is portable and its usage is straightforward, but I have two hesitations:
-
The function needs to ensure that BS5 is in use, so we'd have to either find the root DESCRIPTION file or ask that users include that as an argument. If the gallery were powered by functions called by
build_article(), we could handle this internally. -
Furthermore, pkgdown functions don't tend to make appearances in source code. All other exported functions are intended to be called interactively, but this one would start to appear in source code.
In the YAML front matter
Another option would be to put the gallery items in the YAML front matter as a named list of galleries and then insert the gallery with basic HTML or a special string (here are some brain-storming options)
---
gallery:
examples:
- title: "Setting Up R"
image: images/tutorial-ex-setup-r.png
link: https://learnr-examples.shinyapps.io/ex-setup-r/
---
<div class="gallery" id="examples"></div>
[]{.gallery #examples}
<!--gallery: examples -->
<gallery id="examples">This above YAML structure for example might not be sufficient, we might have to have a very nested yaml list if we allow the gallery to have some options like number of columns or matching height rows.
Some advantages of this method are that we know everything we need to know at build time.
In a gallery chunk
Another option I've considered would be to introduce a gallery knitr engine that takes YAML and inserts the HTML as needed. We'd install the knitr engine in the pkgdown article format that could even implement different versions for BS5 and BS3 (if we want). We could use chunk options to set options specifically for individual galleries.
```{gallery ncol=3}
- title: "Setting Up R"
image: images/tutorial-ex-setup-r.png
link: https://learnr-examples.shinyapps.io/ex-setup-r/
- title: "Filtering Observations"
image: images/tutorial-ex-data-filter.png
link: https://learnr-examples.shinyapps.io/ex-data-filter/
```