quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
4k stars 328 forks source link

Incorrectly specified `{leaflet}` tile provider breaks seemingly all JS components in standalone HTML #9897

Closed jack-davison closed 6 months ago

jack-davison commented 6 months ago

Bug description

In R, if you muck up your {leaflet} provider, not only does the map not render (as one would expect) but it appears to break everything interactive in the report - incl. plotly graphs. This was a particularly destructive typo that cost me a lot of time trying to debug, as the document I was rendering was very big with only a couple of maps.

I'm not sure if this is an issue with Quarto or the R leaflet package.

Steps to reproduce

---
title: "TEST QMD"
format: html
editor_options: 
  chunk_output_type: console
---

```{r}
#| label: wrongleaflet

library(leaflet)
leaflet() |> addProviderTiles("CartoDB.Postron") ## NB - This provider is misspelled on purpose
#| label: fineplotly

library(plotly)

plot_ly(iris, x = ~Sepal.Length) |> add_histogram()

### Expected behavior

I would imagine the `{leaflet}` map would look dodgy, but everything else (other maps, plotly graphs, reactable/DT tables, etc.) would render contentedly.

### Actual behavior

The plotly graphic has not rendered at all:

![image](https://github.com/quarto-dev/quarto-cli/assets/45171616/fccd43df-bacb-4c0a-a9b9-270c45b00f9f)

### Your environment

- IDE: RStudio 2024.04.1+748
- OS: Windows 10

### Quarto check output

```bash
[>] 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:\Program Files\Quarto\bin
      CodePage: 1252

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.9.13
      Path: C:/Program Files (x86)/Microsoft Visual Studio/Shared/Python39_64/python.exe
      Jupyter: 5.1.0
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.3.2
      Path: C:/PROGRA~1/R/R-43~1.2
      LibPaths:
        - C:/Users/JD38/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.2/library
      knitr: 1.45
      rmarkdown: 2.25

[>] Checking Knitr engine render......OK
mcanouil commented 6 months ago

Thanks for the report. Could you try using Quarto 1.4, at least?

jack-davison commented 6 months ago

Certainly - that was using my work PC that our IT controls, so the quarto version is a bit old. I've tried with another device running Quarto 1.4.555 and have the same issue.

![image](https://github.com/quarto-dev/quarto-cli/assets/45171616/1eb4b5ce-7e65-4614-8c61-37baedcc9ea5)
Quarto 1.4.555
[>] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
      Version: 1.4.555
      Path: C:\Users\JD38\AppData\Local\Programs\Quarto\bin
      CodePage: 1252

[>] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[>] Checking LaTeX....................OK
      Tex:  (not detected)

[>] Checking basic markdown render....OK

[>] Checking Python 3 installation....OK
      Version: 3.12.1
      Path: C:/Users/JD38/AppData/Local/Programs/Python/Python312/python.exe
      Jupyter: 5.5.1
      Kernels: python3

[>] Checking Jupyter engine render....OK

[>] Checking R installation...........OK
      Version: 4.3.3
      Path: C:/PROGRA~1/R/R-43~1.3
      LibPaths:
        - C:/Users/JD38/AppData/Local/R/win-library/4.3
        - C:/Program Files/R/R-4.3.3/library
      knitr: 1.46
      rmarkdown: 2.26

[>] Checking Knitr engine render......OK
gadenbuie commented 6 months ago

In R, if you muck up your {leaflet} provider, not only does the map not render (as one would expect) but it appears to break everything interactive in the report - incl. plotly graphs. This was a particularly destructive typo that cost me a lot of time trying to debug, as the document I was rendering was very big with only a couple of maps.

Hi @jack-davison, I think that if there's something to be done here it'd have to come from the leaflet package. The problem is that leaflet (the javascript library) throws an error with the misspelled tile provider. It's a lot like throwing an error in R, when the unhandled error happens the browser stops executing the rest of the JavaScript code.

If you run into these kinds of problems where something is wrong when you open the document in the browser, you can try right clicking on the page and selecting "Inspect" or "Inspect Element" to bring up the developer console in the browser. Then click on the Console tab, where you may find logged errors:

Screenshot of the Console tab of Chrome's developer console, where an error from leaflet providers is shown, reading 'Uncaught No such variant of CartoDB (Postron)'

leaflet may be able to catch this kind of error earlier, or there may be reasons why we can't validate the tile provider names. In any case, if you want to open an issue in leaflet, we'll take a look when we can.

gadenbuie commented 6 months ago

I missed that you already opened https://github.com/rstudio/leaflet/issues/921. I think we can close this issue and see about handling this on the R side.

cderv commented 6 months ago

Thanks @gadenbuie !