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

Building PDFs: net::ERR_ABORTED #49

Open
csgillespie opened this issue May 20, 2022 · 12 comments
Open

Building PDFs: net::ERR_ABORTED #49

csgillespie opened this issue May 20, 2022 · 12 comments

Comments

@csgillespie
Copy link

I'm having trouble building PDF slides.

  • Ubuntu 22.04
  • R 4.2
  • Tried multiple files, same error
  • It works first time on my colleagues' laptops; except they are using Ubuntu 20.04
  • Not sure what else to provide (I know, vague bug, sorry)
❯ xaringanBuilder::build_pdf("chapter1.Rmd")
✔ Building chapter1.Rmd into chapter1.html ... done
✖ Building chapter1.html into chapter1.pdf ... failed
Error in force(expr) : 
  Failed to generate output. Reason: net::ERR_ABORTED
Run `rlang::last_error()` to see where the error occurred.
✖ [77-support-building-slides-to-pdf*]
❯ last_error()
<error/rlang_error>
Error:
! Failed to generate output. Reason: net::ERR_ABORTED
Caused by error in `force()`:
! Failed to generate output. Reason: net::ERR_ABORTED
---
Backtrace:
 1. xaringanBuilder::build_pdf("chapter1.Rmd")
 2. xaringanBuilder:::build_pdf_simple(step_html, output_file)
      at xaringanBuilder/R/pdf.R:92:8
 3. base::tryCatch(...)
      at xaringanBuilder/R/pdf.R:98:4
 4. base tryCatchList(expr, classes, parentenv, handlers)
 5. base tryCatchOne(expr, names, parentenv, handlers[[1L]])
 6. value[[3L]](cond)
Run `rlang::last_trace()` to see the full context.
✔ [77-support-building-slides-to-pdf*]

❯ sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] jrPresentation2_0.3.3

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8.3          gert_1.6.0            ps_1.7.0              rprojroot_2.0.3       digest_0.6.29         prompt_1.0.1          utf8_1.2.2            prettycode_1.1.0      R6_2.5.1             
[10] xaringanBuilder_0.0.9 sys_3.4               evaluate_0.15         xaringan_0.24         pillar_1.7.0          rlang_1.0.2           lazyeval_0.2.2        callr_3.7.0           jquerylib_0.1.4      
[19] rmarkdown_2.14        config_0.3.1          desc_1.4.1            servr_0.24            stringr_1.4.0         httpuv_1.6.5          compiler_4.2.0        lintr_2.0.1           xfun_0.31            
[28] pkgconfig_2.0.3       askpass_1.1           htmltools_0.5.2       openssl_2.0.0         websocket_1.4.1       tibble_3.1.7          fansi_1.0.3           memuse_4.2-1          crayon_1.5.1         
[37] withr_2.5.0           later_1.3.0           jsonlite_1.8.0        lifecycle_1.0.1       magrittr_2.0.3        credentials_1.3.2     cli_3.3.0             stringi_1.7.6         cachem_1.0.6         
[46] rprofile_0.1.11       fs_1.5.2              promises_1.2.0.1      remotes_2.4.2         rex_1.2.1             xml2_1.3.3            bslib_0.3.1           ellipsis_0.3.2        vctrs_0.4.1          
[55] cyclocomp_1.1.0       tools_4.2.0           glue_1.6.2            rdoc_0.1.0            rsconnect_0.8.25      processx_3.5.3        parallel_4.2.0        fastmap_1.1.0         yaml_2.3.5           
[64] chromote_0.1.0        memoise_2.0.1         knitr_1.39            pagedown_0.18         sass_0.4.1           
@gadenbuie
Copy link
Collaborator

The version of build_pdf() being called here is essentially a small wrapper around pagedown::chrome_print(), so I'd suggest trying that function on its own to see if you can get a more informative error message.

To closely replicate our flow, you could use build_html() to build the html file and then call

pagedown::chrome_print(
  input  = "chapter1.html",
  output = "chapter1.pdf"
)

@gadenbuie
Copy link
Collaborator

gadenbuie commented May 20, 2022

It does smell like there's something wrong with chrome/chromote going on here

@jhelvy
Copy link
Owner

jhelvy commented May 20, 2022

So it's working on Ubuntu 20.04 but not Ubuntu 22.04? Sounds like an issue with Chrome.

Another check is to try and print some other webpage, like pagedown::chrome_print("https://en.wikipedia.org/wiki/R_(programming_language)")

If you get a similar error, then that should at least help narrow down the source.

@csgillespie
Copy link
Author

So this is odd. This works

pagedown::chrome_print("https://en.wikipedia.org/wiki/R_(programming_language)",
                       output = "wiki.pdf")

But this doesn't

pagedown::chrome_print(
  input  = "chapter1.html",
  output = "chapter1.pdf"
)

Chapter1.Rmd now looks like

---
title: "Introduction"
output:
  xaringan::moon_reader
---

@jhelvy
Copy link
Owner

jhelvy commented May 20, 2022

Can you try this?

pagedown::chrome_print(
  input  = "file://chapter1.html",
  output = "chapter1.pdf"
)

@csgillespie
Copy link
Author

❯ pagedown::chrome_print(
  input  = "file://chapter1.html",
  output = "chapter1.pdf"
)
Error in force(expr) : 
  Failed to generate output. Reason: net::ERR_INVALID_URL
Run `rlang::last_error()` to see where the error occurred.
✖ [main* ↓]
❯ last_error()
<error/rlang_error>
Error:
! Failed to generate output. Reason: net::ERR_INVALID_URL
---
Backtrace:
 1. pagedown::chrome_print(input = "file://chapter1.html", output = "chapter1.pdf")
 2. later with_temp_loop_maybe(...)
 3. later::with_loop(loop, expr)
 4. base::force(expr)
Run `rlang::last_trace()` to see the full context.
✔ [main* ↓]
❯ last_trace()
<error/rlang_error>
Error:
! Failed to generate output. Reason: net::ERR_INVALID_URL
---
Backtrace:
    ▆
 1. └─pagedown::chrome_print(input = "file://chapter1.html", output = "chapter1.pdf")
 2.   └─later with_temp_loop_maybe(...)
 3.     └─later::with_loop(loop, expr)
 4.       └─base::force(expr)

@gadenbuie
Copy link
Collaborator

You'll need the absolute path prefixed with file://, which ends up being file:///Users/colin/chapter1.html

@csgillespie
Copy link
Author

You'll need the absolute path prefixed with file://, which ends up being file:///Users/colin/chapter1.html

Duh! I did that the first time, and got an error. Must have had a typo :(

pagedown::chromepagedown::chrome_print(
  input  = "file:///data/ncsg3/gitlab/training/r/introduction/slides/chapter1.html",
  output = "chapter1.pdf"
)

works!

@gadenbuie
Copy link
Collaborator

But you still get the error when using build_pdf()? I wonder if you could try

debug(xaringanBuilder:::build_pdf_simple)
xaringanBuilder::build_pdf("chapter1.Rmd")

And check that the file path for input is correct. Some other things to take a look at:

  1. Does your source doc use self_contained = TRUE?
  2. Does your source doc reference files from other directories, like a CSS file in a parent directory?

The net::ERR_ABORTED error seems like maybe it's some kind of 404-equivalent error, but beyond that I'm just making guesses. I was surprised that pagedown::chrome_print() worked as expected, I was thinking that would give us a better hint. 🤔

@csgillespie
Copy link
Author

My chapter1.Rmd is now minimal. It's only five lines:

---
title: "Introduction"
output:
  xaringan::moon_reader
---

This

input = "file:///data/ncsg3/gitlab/training/r/introduction/slides/chapter1.html"
output = "/data/ncsg3/gitlab/training/r/introduction/slides/chapter1.pdf"
pagedown::chrome_print(input = input, output = output, verbose = 2)

works fine. But if I remove the explicit file:://, I get the error.


Interestingly,

---
title: "Introduction"
---

works with no issues. So there is something odd around xaringan for me.

@wesleyburr
Copy link

One more tiny piece of information on this: Ubuntu 20.04, Chrome Version 101.0.4951.54 (Official Build) (64-bit). Similarly having failures on build_pdf() -

✖ Building xaringanBuilder_3805fa20d95692.html into xaringanBuilder_3805fa78b5fac.pdf ... failed
Error in force(expr) :
Failed to generate output. Reason: Failed to open http://127.0.0.1:5677/figure/infer_oregon3.png (HTTP status code: 404)

Adding the manual explicit full file path to the input sails through:

xaringanBuilder:::build_pdf_simple("file:///home/path/to/file/here/index.html", "index.pdf")

Input is just a bog-standard set of slides for a presentation. Maybe the 404 that's bouncing reinforces the comment by gadenbuie above.

@csgillespie
Copy link
Author

@wesleyburr / @gadenbuie I had a "similar" issue with RStudio. Essentially when opening an HTML file, it used firefox. The issue was that the default browser for opening a file was firefox.

Firefox can't open local assets on my machine, so could, I suppose, generate the above errors. I wonder if that is the issue?

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

No branches or pull requests

4 participants