R markdown compile error:

25,239

Solution 1

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

Solution 2

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)

Share:
25,239
wolfsatthedoor
Author by

wolfsatthedoor

Updated on July 09, 2022

Comments

  • wolfsatthedoor
    wolfsatthedoor almost 2 years

    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?

    • Alex
      Alex about 7 years
      How does your markdown file looks like? Do you have any function which produces html or java script output e.g. tables or plots?
    • wolfsatthedoor
      wolfsatthedoor about 7 years
      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
    • Alex
      Alex about 7 years
      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.
    • wolfsatthedoor
      wolfsatthedoor about 7 years
      Ok thank you, I think it is from using plotly, instead of ggplot2
    • scoa
      scoa about 7 years
      @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.
    • Rivka
      Rivka over 5 years
      I used to have trouble with this, when using plotly graphs in my output. After changing back to ggplot for the pdf (and keeping the plotly ones for html) everything worked fine.
  • the_SJC
    the_SJC over 3 years
    Thanks, this saved me significant time in producing an R Markdown document that can create an html with interactive plotly and a Word document without any extra work!