12
votes

When I try to compile an Rmarkdown document to pdf, I get this error:

    Error: Functions that produce HTML output found in document targeting latex 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 of
your rmarkdown file:

  always_allow_html: yes

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

Does anyone know what this means?

3
How does your markdown file looks like? Do you have any function which produces html or java script output e.g. tables or plots? - Alex
I have plots yes. I can't reproduce because when I do a simple rmd, it works, it only doesn't work on the totality of it. I am wondering what this error even means exactly - wolfsatthedoor
It says that some function produces html output which is not suitable for a latex document. But I guess you can read that yourself. You could try to compile it to an html document and see if that works. - Alex
Ok thank you, I think it is from using plotly, instead of ggplot2 - wolfsatthedoor
@robertevansanders "I can't reproduce because when I do a simple rmd, it works, it only doesn't work on the totality of it": I think you can reproduce: just remove chunks and try to compile until the error disappears ; the last removed chunk is the one with the problem. You can then post a MCVE with just this code. - scoa

3 Answers

16
votes

Have you tried the following? (FROM: https://bookdown.org/yihui/bookdown/html-widgets.html)

install.packages("webshot")
webshot::install_phantomjs()

It worked for me. See also: https://github.com/rstudio/bookdown/issues/440

10
votes

I ran into this problem when using Bookdown, and the accepted solution did not work in my context. I resolved it after figuring out what the "YAML front-matter of your RMarkdown file" is. With bookdown, there is a .travis.yml file and a _bookdown.yml file, but you want to leave these two alone and these are not what the error message is referencing.

The "front-matter" would be the top of your RMarkdown file (if using bookdown it would be the "index.Rmd" file), see screenshot below: enter image description here

So just add always_allow_html: yes to the YAML header as its own line and it should work as expected (or give you a different error)

0
votes

You need to choose what format you want to KNIT to, tried to look at mine.

---
title: "<img src='www/binary-logo.jpg' width='240'>"
subtitle: "[<span style='color:blue'>binary.com</span>](https://github.com/englianhu/binary.com-interview-question) Interview Question I"
author: "[<span style='color:blue'>®γσ, Lian Hu</span>](https://englianhu.github.io/) <img src='www/ENG.jpg' width='24'> <img src='www/RYO.jpg' width='24'>白戸則道®"
date: "`r Sys.Date()`"
output:
  tufte::tufte_html:
    toc: yes
  tufte::tufte_handout:
    citation_package: natbib
    latex_engine: xelatex
  tufte::tufte_book:
    citation_package: natbib
    latex_engine: xelatex
link-citations: yes
---

KNIT