quarto-dev / quarto-dev/quarto-cli
R Leaflet legends are centered when labelled as `fig-`s
- Dominant language
- JavaScript
- Stars
- 6k
- Forks
- 458
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 41
Description
Bug description
When a leaflet map is included in a Quarto HTML report, any categorical legend ends up centered when the chunk is labelled as a figure. This looks a little strange/ugly, particularly when the labels are either very different lengths or are only subtly different lengths. Oddly, if you just print the leaflet map without labelling it as a figure, everything works okay.
Note that you can manually fix this by adding this to a style tag, but I imagine this isn't the intended fix, and that messing around with quarto's style options may have unintended consequences.
.quarto-figure-center>figure>p, .quarto-figure-center>figure>div {
text-align: left;
}
No idea if this happens with Python/Folium, but I intuitively expect so?
Steps to reproduce
---
title: Dodgy leaflet
format: html
---
```{r}
#| label: makemap
library(leaflet)
map <-
leaflet() |>
addTiles() |>
addLegend(
labels = c("Big long label oh no!", "lil' lab"),
colors = c("red", "blue")
)
```
```{r}
#| label: fig-leaflet
#| fig-cap: "A leaflet figure"
map
```
```{r}
#| label: nolab
map
```
Expected behavior
The leaflet legend should be left aligned (bottom of image).
Actual behavior
The leaflet legend is centered (top of image).
Your environment
- RStudio 2023.03.0+386
- Windows 10
Quarto check output
$ quarto check
A new release of Deno is available: 1.28.2 → 1.38.5 Run `deno upgrade` to install it.
[>] Checking versions of quarto binary dependencies...
Pandoc version 3.1.1: OK
Dart Sass version 1.55.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
Version: 1.3.450
Path: C:\Users\jd38\AppData\Local\Programs\Quarto\bin
CodePage: 1252
[>] Checking basic markdown render....OK
[>] Checking Python 3 installation....(None)
Unable to locate an installed version of Python 3.
Install Python 3 from https://www.python.org/downloads/
[>] Checking R installation...........OK
Version: 4.2.3
Path: C:/Users/jd38/AppData/Local/Programs/R/R-4.2.3
LibPaths:
- C:/Users/jd38/AppData/Local/R/win-library/4.2
- C:/Users/jd38/AppData/Local/Programs/R/R-4.2.3/library
knitr: 1.44
rmarkdown: 2.25
[>] Checking Knitr engine render......OK
NB: I'm using R leaflet v2.2.0.9000.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.