0

I have a R-Markdown file that includes some HTML-output that I want to knit to a pdf. My question is, is there a way of capturing the output of the Viewer and include it automatically.

For example, consider the following MWE:

---
title: "Include Viewer in PDF"
author: "Myself"
date: "today"
output:
  pdf_document: default
always_allow_html: yes
---
```{r}
library(stringr)
str_view("hello world", "o\\s[sw]")
```

If I use knit to HTML, the result is shown properly: image1

If I use knit to PDF, the result is not shown at all (because I used always_allow_html: yes, however if I exclude that specification, I get the error: Error: Functions that produce HTML output found in document targeting latex output. ...): image2

Any ideas?

David
  • 9,216
  • 4
  • 45
  • 78

1 Answers1

1

Alright, I found a solution. Thanks to this question, which directed me towards the webshot-library.

So install webshot and run webshot::install_phantomjs() if necessary. Now knitr is able to take a screenshot of the Viewer automatically.

The PDF-code above now yields:

enter image description here

David
  • 9,216
  • 4
  • 45
  • 78
  • Unfortunately, this is not working for me. The output I get is really small, barely readable. Any way to control the output size? – skd Jan 14 '19 at 16:15