Chapter 16 HTML Widgets

We briefly mentioned HTML widgets in the beginning of this book in Section 2.8.1. The htmlwidgets package (Vaidyanathan et al. 2020) provides a framework for creating R bindings to JavaScript libraries. HTML Widgets can be:

  • Used at the R console for data analysis just like conventional R plots.

  • Embedded within R Markdown documents.14

  • Incorporated into Shiny web applications.

  • Saved as standalone web pages for ad-hoc sharing via Email and Dropbox, etc.

There have been many R packages developed based on the HTML widgets framework, to make it easy for R users to create JavaScript applications using pure R syntax and data. It is not possible to introduce all these R packages in this chapter. Readers should read the documentation of specific widget packages for the usage. This chapter is mainly for developers who want to bring more JavaScript libraries into R, and it requires reasonable familiarity with the JavaScript language.

References

Vaidyanathan, Ramnath, Yihui Xie, JJ Allaire, Joe Cheng, Carson Sievert, and Kenton Russell. 2020. Htmlwidgets: HTML Widgets for R. https://github.com/ramnathv/htmlwidgets.


  1. Note that interactivity only works when the output format is HTML, including HTML documents and presentations. If the output format is not HTML, it is possible to automatically create and embed a static screenshot of the widget instead. See Section 2.8.1 for more information.↩︎