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

error with pdf output and html function (leaflet) #3279

Closed
4 tasks done
ericvmai opened this issue Nov 10, 2022 · 9 comments
Closed
4 tasks done

error with pdf output and html function (leaflet) #3279

ericvmai opened this issue Nov 10, 2022 · 9 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request
Milestone

Comments

@ericvmai
Copy link

Bug description

I have the below code in a Quarto project and I'm trying to render to pdf.

#| label: fig-ash-map
#| fig-cap: "Map of Town of Ashland"

ashland <- st_read('https://services2.arcgis.com/sKZWgJlU6SekCzQV/arcgis/rest/services/Ashland_Boundary/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson', quiet = TRUE)

leaflet(ashland) %>% 
  addTiles() %>% 
  addPolygons()

I get the following error that was not occurring previously:

Error: Functions that produce HTML output found in document targeting pdf output.Please change
the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter ofyour quarto file:

prefer-html: true

Note however that the HTML output will not be visible in non-HTML formats.

I've updated quarto cli to the 1.2.269 Candidate Release on Windows 11 Pro. It worked fine on my other machine and all packages are updated. My yml includes the following settings for pdf export:

knitr:
opts_chunk:
echo: false
warning: false
message: false

format:
html:
theme: lumen
pdf:
documentclass: scrreprt

Please help! I was having no issue with Quarto exporting these out to a pdf previously but am now all of a sudden.

Checklist

  • Please include a minimal, fully reproducible example in a single .qmd file? Please provide the whole file rather than the snippet you believe is causing the issue.
  • Please format your issue so it is easier for us to read the bug report.
  • Please document the RStudio IDE version you're running (if applicable), by providing the value displayed in the "About RStudio" main menu dialog?
  • Please document the operating system you're running. If on Linux, please provide the specific distribution.
@ericvmai ericvmai added the bug Something isn't working label Nov 10, 2022
@ericvmai ericvmai reopened this Nov 11, 2022
@cscheid
Copy link
Collaborator

cscheid commented Nov 13, 2022

Thanks for the report. Can you share the full .qmd that is causing trouble for you?

@cscheid cscheid added the needs-repro Issues that are blocked until reporter provides an adequate reproduction label Nov 13, 2022
@ericvmai
Copy link
Author

Providing a link to that qmd at our public repo.

https://github.com/hdadvisors/rrh-framework/blob/main/part-4-9.qmd

@cscheid
Copy link
Collaborator

cscheid commented Mar 8, 2023

Sorry for the delay on getting back to you. I confess I don't quite know how you got PDF support in leaflet; I've tried rendering with quarto versions going back to 1.0.38 and I see the same problem. I believe leaflet requires PDF support, at least in the way you're making that call. I'm attaching the repro file I'm using. I'm going to go ahead and close this one, but if you can point to a quarto release and minimal file for which a PDF build worked for you, please feel free to reopen.

---
title: issue-3279
knitr:
  opts_chunk: 
    echo: false
    warning: false
    message: false

format:
  html:
    theme: lumen
  pdf:
    documentclass: scrreprt
---

```{r}
#| label: fig-ash-map
#| fig-cap: "Map of Town of Ashland"

library(sf)
library(leaflet)

ashland <- st_read('https://services2.arcgis.com/sKZWgJlU6SekCzQV/arcgis/rest/services/Ashland_Boundary/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson', quiet = TRUE)

leaflet(ashland) %>% 
  addTiles() %>% 
  addPolygons()
```

@cscheid cscheid closed this as completed Mar 8, 2023
@cderv
Copy link
Collaborator

cderv commented Mar 8, 2023

Related to #4225 probably where I need to update the documentation.

Using HTMLWIDGETS in document using R with Quarto works the same way as with rmarkdown. Screenshot of the html widgets will be made. For that webshot or preferably webshot2 R package is required. See the issue linked for explication in my comments

Do you have one of those package installed ? If not, then it won't work. If you do, the PDF will render with a screenshot of the leaflet.

@cscheid your example works for me and produce this PDF.
test2.pdf

Improving the indication on what to do is part of work I need to do for #4225

@cscheid
Copy link
Collaborator

cscheid commented Mar 8, 2023

Ah, I don't have webshot2 installed (maybe we should tell users that).

And it does seem like this causes a bug, because the output is different.

@cscheid cscheid reopened this Mar 8, 2023
@cscheid cscheid added this to the v1.4 milestone Mar 8, 2023
@cscheid cscheid added the enhancement New feature or request label Mar 8, 2023
@cderv
Copy link
Collaborator

cderv commented Mar 8, 2023

Ah, I don't have webshot2 installed (maybe we should tell users that).

This is R only feature to wonder how we want to warn about that, but my plan is to add to documentation for knitr computation as part of #4225 which is the same issue.

And it does seem like this causes a bug, because the output is different.

What bug exactly ? It is working for me unless I missed something

@cscheid
Copy link
Collaborator

cscheid commented Mar 8, 2023

They generate different figures (the HTML one is centered on the polygon for me, but the PDF one isn't).

@cderv
Copy link
Collaborator

cderv commented Mar 8, 2023

Oh I see now. I missed this. I think I may know why (related to size option on cells that we use with webshot() to determine what to snapshot.

R Markdown gives a different results so something we do in Quarto.

---
title: test
output: 
  pdf_document:
    keep_md: true
---

```{r}
#| label: fig-ash-map
#| fig-cap: "Map of Town of Ashland"

library(sf)
library(leaflet)

ashland <- st_read('https://services2.arcgis.com/sKZWgJlU6SekCzQV/arcgis/rest/services/Ashland_Boundary/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson', quiet = TRUE)

leaflet(ashland) %>% 
  addTiles() %>% 
  addPolygons()
```

test.pdf

@cderv cderv removed the needs-repro Issues that are blocked until reporter provides an adequate reproduction label Mar 8, 2023
@cderv cderv self-assigned this Mar 8, 2023
@cderv
Copy link
Collaborator

cderv commented Nov 23, 2023

@ericvmai I'll close this one because the initial error is fixed.

Regarding the different rendering with webshot2 doing the screenshot, I believe this because

and screenshot needs to be done with png format, and not pdf.

This will work

---
title: test
format: pdf
---

```{r}
#| label: fig-ash-map
#| fig-cap: "Map of Town of Ashland"
#| fig-format: png 

library(sf)
library(leaflet)

ashland <- st_read('https://services2.arcgis.com/sKZWgJlU6SekCzQV/arcgis/rest/services/Ashland_Boundary/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson', quiet = TRUE)

leaflet(ashland) %>% 
  addTiles() %>% 
  addPolygons()
```

image

I'll open an issue to remember to think of an improvement in Quarto or knitr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants