Bookdown error when building to word doc

I have a bookdown project that I'm trying to output as a Word document. I added the following to _output.yml and saved:

  toc: true

And when I try to build the book, I get this error:

Error: Functions that produce HTML output found in document targeting docx 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: true

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

Execution halted

Exited with status 1.

The project has ggplots and tables using DT and kable. I already have webshot installed, I double checked:

> webshot::is_phantomjs_installed()
[1] TRUE

Building to a PDF works fine, the problem is only when trying to build to a word document. If anyone has any suggestions that would be great. My thesis is due in a couple days :sweat_smile:

Unfortunately, I can't reproduce this. When the screenshot is working for PDF, it is always working for WORD output.

What exactly is the HTML content you have in your book ? Is this only HTML widgets ?

The screenshot will only be done automatically for supported format (widgets and shinyapps mainly). If you are using other type of HTML output (maybe a HTML table ?), there will be no screenshot.

Can you identify the type of content (HTML Widgets I guess) you are using ? It seems that one is not getting screenshoted while rendering to word.

No that you can force screenshot by setting screenshot.force to TRUE in a chunk that would require it. But it should be automatically be set to TRUE for chunks outputing object of class htmlwidget.

Something ike setting the knitr option screenshot.force = knitr::pandoc_to("docx") like could maybe force the screenshot to happen, but you would need to know on which chunk to put it.

anyway, this is supposed to work. Specifically if it works for PDF, it should work for WORD.

Without more details, it will be difficult to help more. You'll need to look closer in your book content to find what is creating this.

Hope you'll find it!

If you're not sure where, here's a tip for finding it.

  1. Duplicate your book folder and do this next part in the duplicate folder so you don't accidentally mess up your book.
  2. Delete the vast majority of the book and try building to Docx again, just to make sure it works at all on your system.
  3. If it doesn't, you know the issue is either in the small amount of book left or in producing a docx at all. If it does, then add the first half of the book and try to build it. You can quickly narrow down what specific part(s) is causing problems by splitting stuff in half and trying with each half.

Maybe you already know all that, but if not, I hope it helps a bit and saves you a bit of time.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.