Pagedown package error in producing the output

176 Views Asked by At

I have recently decided to use pagedown package in producing pdf and html outputs and therefore installed the library. I am trying to run the very simple Rmd file that comes as default when I choose to use pagedown file as my new file in the RStudio.

Here is the Rmd file content if you would like to see;

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    number_sections: FALSE
# uncomment this line to produce HTML and PDF in RStudio:
knit: pagedown::chrome_print 
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# Introduction

This is an example of a multi-page HTML document with some options shown in YAML header. See https://pagedown.rbind.io for the full documentation. The rest of this document is random text.

# Random text

```{r, results='asis', echo = FALSE}
random_markdown = function(len = 100) {
  uri = knitr::image_uri(file.path(R.home('doc'), 'html', 'logo.jpg'))
  text = function(len) {
    trimws(paste(sample(c(letters, rep(' ', 10)), len, TRUE), collapse = ''))
  }
  id = function() paste(sample(letters, 8, TRUE), collapse = '')
  figure = function(i = id()) {
    sprintf('![(#fig:%s)The R logo.](%s){width=%d%%}', i, uri, sample(20:60, 1))
  }
  tab = paste(knitr::kable(head(mtcars[, 1:5])), collapse = '\n')
  table = function(i = id()) {
    c(sprintf('Table: (#tab:%s)A table example.', i), tab)
  }
  unlist(lapply(seq_len(len), function(i) {
    if (i %% 20 == 0) return(paste('#', text(sample(10:30, 1))))
    if (i %% 10 == 0) return(paste('##', text(sample(10:30, 1))))
    # insure some elements
    if (i == 3) return(text(50))
    if (i == 4) return(figure("md-fig"))
    if (i == 5) return(text(50))
    if (i == 6) return(table("md-tab"))
    # then random
    type = sample(1:3, 1, prob = c(.9, .03, .07))
    switch(type, text(sample(50:300, 1)), figure(), table())
  }))
}
cat(random_markdown(), sep = '\n\n')


# Knitr inserted Figures and tables

## Simple graphics
```

Until here, R markdown can run the document well. However, when I tried to add the following two code chunks, the document fails to run.

``` {r simple-graphic, fig.cap = 'A very simple plot'}
plot(1)
```

## Simple tables

```{r simple-table}
knitr::kable(head(mtcars, 3), caption = "A Simple table")
```

And here is the error I get;

Error in force(expr) : Failed to generate output in 30 seconds (timeout).
Calls: <Anonymous> -> with_temp_loop_maybe -> with_loop -> force
Closing websocket connection
Closing browser
Cleaning browser working directory
Closing local webserver

I do not understand why the document does not fail to run in the first phase, while it fails to run in the second step. I tried to find a solution through web. I hope I am clear regarding my problem and I look forward to your reply. Thank you for your understanding beforehand.

1

There are 1 best solutions below

0
Daniel_j_iii On

If you just remove knit: pagedown::chrome_print the document will render to HTML just fine, Then from here, you can "print to PDF" from the browser to get both an HTML and a PDF doc of the output

---
title: "A Multi-page HTML Document"
author: "Yihui Xie and Romain Lesur"
date: "`r Sys.Date()`"
output:
  pagedown::html_paged:
    number_sections: FALSE
---

I think the issue might be your are specifying 2 different output formats, and Rmarkdown is taking a long time to render these

There is a similar issue discussed here the advice was to increase the timeout value, as it's default is 30 seconds until the process is fails out. and another similar issue here... but to be honest, I was not able to correct apply the timeout argument in chrome_print enter image description here