Not surprisingly, HTML widgets were designed for HTML output formats (e.g., rmarkdown::html_document and rmarkdown::ioslides_presentation). Their interactivity relies on JavaScript. In general, you should not expect JavaScript to work in LaTeX/PDF or Word or PowerPoint.
In January 2015, I gave an introductory talk on HTML widgets in the LA R User Group. I joked in the talk that “If you ask me how to use HTML widgets in Word or LaTeX, we cannot be friends .” (I meant, how could you possibly ask such a question?) A year later, this became only a half joke.
While developing bookdown in 2016, I added a feature in knitr to “support” HTML widgets for non-HTML output, which basically means if the output is not HTML, knitr will try to use the webshot package to automatically take a screenshot of the widget, and embed the static screenshot in the output. Of course, you won’t be able to interact with this static image, but it may be better than nothing (or throwing an error).
The detailed documentation about this feature can be found in Section 2.10 of the bookdown book.
Similarly, Shiny apps won’t work in non-HTML output, either. If you want to include a screenshot of a Shiny app in a knitr document, you may explicitly use the knitr::include_app() function after you publish the app to a server. More generally, you can include a screenshot of any web page via knitr::include_url() when the output format is not HTML.
Screenshotting HTML widgets, Shiny apps, and arbitrary URLs works in any non-HTML output formats: PDF, Word, EPUB, RTF, and PowerPoint, etc. If you want, you may even force a screenshot in HTML output, too (see documentation).
I’d like to thank Winston for the heavy-lifting in the webshot package. It is a very neat package.
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:xie@yihui.name -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
xie@yihui.name. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).