Pagedown: chrome_print and Error in websocket callback: C stack usage 11960482 is too close to the limit

Created on 13 Nov 2020  ·  3Comments  ·  Source: rstudio/pagedown

Dear all,

I am having an issue with one html file (bigger than the other ones). it failed to render the pdf, so I gave him more time to do it:

 pagedown::chrome_print("docs/lectures/lecture06_plotting.html", verbose = 2, timeout = 180)

the logs are:

Message received from headless Chrome: {"method":"Page.frameResized","params":{},"sessionId":"B88A0BCB2845FA3FB23DF18281E73598"}
Message received from headless Chrome: {"method":"Page.frameResized","params":{},"sessionId":"B88A0BCB2845FA3FB23DF18281E73598"}
Error in websocket callback: C stack usage  11960482 is too close to the limit
Message received from headless Chrome: {"method":"Page.frameResized","params":{},"sessionId":"B88A0BCB2845FA3FB23DF18281E73598"}
Message received from headless Chrome: {"method":"Page.frameResized","params":{},"sessionId":"B88A0BCB2845FA3FB23DF18281E73598"}
Error in force(expr) : 
  Failed to generate output in 180 seconds (timeout).
Closing websocket connection
Closing browser
Cleaning browser working directory
Closing local webserver

the blocking steps are franeResized. I tried the self_contained of xaringan to TRUE or FALSE, doesn't change the outcome.

Many thanks for your help

pagedown: v0.12
xaringan:  v0.18
````

<sup>Created on 2020-11-13 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
<details>
<summary>
Session info
</summary>

``` r
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Ubuntu 20.04.1 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en                          
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-11-13                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  ! package     * version date       lib source        
#>  P assertthat    0.2.1   2019-03-21 [?] CRAN (R 4.0.0)
#>  P backports     1.2.0   2020-11-02 [?] CRAN (R 4.0.3)
#>  P callr         3.5.1   2020-10-13 [?] CRAN (R 4.0.3)
#>  P cli           2.1.0   2020-10-12 [?] CRAN (R 4.0.3)
#>  P crayon        1.3.4   2017-09-16 [?] CRAN (R 4.0.0)
#>  P desc          1.2.0   2018-05-01 [?] CRAN (R 4.0.0)
#>  P devtools      2.3.2   2020-09-18 [?] CRAN (R 4.0.2)
#>  P digest        0.6.27  2020-10-24 [?] CRAN (R 4.0.3)
#>  P ellipsis      0.3.1   2020-05-15 [?] CRAN (R 4.0.1)
#>  P evaluate      0.14    2019-05-28 [?] CRAN (R 4.0.0)
#>  P fansi         0.4.1   2020-01-08 [?] CRAN (R 4.0.0)
#>  P fs            1.5.0   2020-07-31 [?] CRAN (R 4.0.2)
#>  P glue          1.4.2   2020-08-27 [?] CRAN (R 4.0.2)
#>  P highr         0.8     2019-03-20 [?] CRAN (R 4.0.0)
#>  P htmltools     0.5.0   2020-06-16 [?] CRAN (R 4.0.2)
#>  P knitr         1.30    2020-09-22 [?] CRAN (R 4.0.2)
#>  P magrittr      1.5     2014-11-22 [?] CRAN (R 4.0.0)
#>  P memoise       1.1.0   2017-04-21 [?] CRAN (R 4.0.1)
#>  P pkgbuild      1.1.0   2020-07-13 [?] CRAN (R 4.0.2)
#>  P pkgload       1.1.0   2020-05-29 [?] CRAN (R 4.0.1)
#>  P prettyunits   1.1.1   2020-01-24 [?] CRAN (R 4.0.0)
#>  P processx      3.4.4   2020-09-03 [?] CRAN (R 4.0.2)
#>  P ps            1.4.0   2020-10-07 [?] CRAN (R 4.0.2)
#>  P R6            2.5.0   2020-10-28 [?] CRAN (R 4.0.3)
#>  P remotes       2.2.0   2020-07-21 [?] CRAN (R 4.0.2)
#>  P renv          0.12.2  2020-11-04 [?] CRAN (R 4.0.3)
#>  P rlang         0.4.8   2020-10-08 [?] CRAN (R 4.0.2)
#>  P rmarkdown     2.5     2020-10-21 [?] CRAN (R 4.0.3)
#>  P rprojroot     1.3-2   2018-01-03 [?] CRAN (R 4.0.0)
#>  P sessioninfo   1.1.1   2018-11-05 [?] CRAN (R 4.0.0)
#>  P stringi       1.5.3   2020-09-09 [?] CRAN (R 4.0.2)
#>  P stringr       1.4.0   2019-02-10 [?] CRAN (R 4.0.0)
#>  P testthat      3.0.0   2020-10-31 [?] CRAN (R 4.0.3)
#>  P usethis       1.6.3   2020-09-17 [?] CRAN (R 4.0.2)
#>  P withr         2.3.0   2020-09-22 [?] CRAN (R 4.0.2)
#>  P xfun          0.19    2020-10-30 [?] CRAN (R 4.0.3)
#>  P yaml          2.2.1   2020-02-01 [?] CRAN (R 4.0.0)
#> 
#> [1] /home/ginolhac/Projects/rworkshop/renv/library/R-4.0/x86_64-pc-linux-gnu
#> [2] /tmp/Rtmp6DRljT/renv-system-library
#> [3] /tmp/RtmpMpM7mY/renv-system-library
#> 
#>  P ── Loaded and on-disk path mismatch.

Most helpful comment

The problem comes from the fact that the whole pdf is sent as a string to the R session. This string cannot be allocated due to R memory limit.
AFAIK, there's no "out of the box" option to resolve this problem.

The first option is to manually print the pdf with Chrome.

If you need to automate the pdf generation, maybe you can try to increase the stack size.
Another option for automation is to split/combine the pdf in two parts. You can use the pageRanges option to do that.
Here's a reprex:

first_part <- pagedown::chrome_print(
  "https://slides.yihui.org/xaringan/", 
  output = "slides_1-20.pdf", 
  options = list(pageRanges = "1-20")
)

second_part <- pagedown::chrome_print(
  "https://slides.yihui.org/xaringan/", 
  output = "slides_21-39.pdf", 
  options = list(pageRanges = "21-39")
)

qpdf::pdf_combine(c(first_part, second_part), "slides.pdf")

All 3 comments

The problem comes from the fact that the whole pdf is sent as a string to the R session. This string cannot be allocated due to R memory limit.
AFAIK, there's no "out of the box" option to resolve this problem.

The first option is to manually print the pdf with Chrome.

If you need to automate the pdf generation, maybe you can try to increase the stack size.
Another option for automation is to split/combine the pdf in two parts. You can use the pageRanges option to do that.
Here's a reprex:

first_part <- pagedown::chrome_print(
  "https://slides.yihui.org/xaringan/", 
  output = "slides_1-20.pdf", 
  options = list(pageRanges = "1-20")
)

second_part <- pagedown::chrome_print(
  "https://slides.yihui.org/xaringan/", 
  output = "slides_21-39.pdf", 
  options = list(pageRanges = "21-39")
)

qpdf::pdf_combine(c(first_part, second_part), "slides.pdf")

thanks a lot Romain, and sorry my html was indeed quite big. Really like your per page range options.

your approach even works in the CI so great! :+1:

Was this page helpful?
0 / 5 - 0 ratings