Word, PowerPoint, Excel, and PDF
Word, PowerPoint, Excel, and PDF are non-HTML formats, hence they do not support the rendering of interactive elements like HTML widgets. To overcome this limitation, we can take a screenshot of the HTML widget and insert the screenshot in the document and thus indirectly embedding the static capture of the widget.
Webshot library in R helps to take screenshots of web pages automating the process of capturing the screenshot after the widget is created rather than us manually capturing screenshots. Before using the webshot package, we need to install it in our R environment. Additionally, the phantomjs tool, which is required by webshot, also needs to be installed.
install.packages("webshot")
webshot::install_phantomjs()
How to Embed htmlwidgets into Documents in R
HTML widgets in R Programming Launagauge are interactive web components, JavaScript-based visualizations that can be easily integrated into different documents. They are built on top of the HTML widgets package, which provides a framework for creating R bindings to JavaScript libraries. Examples of HTML widgets available for R include leaflet, dygraphs, Plotly, DiagrammeR, and others.
HTML widgets can be embedded directly into various types of documents created in R, such as R Markdown files, Shiny web applications, and standalone HTML pages, and even indirectly into documents like Word, Excel, PowerPoint, and PDF files. Embedding HTML widgets into documents ensures reproducibility, eliminating any discrepancies that may arise from the manual re-creation of the same document on different setups and environments.
Prerequisites :-
The various implementations in different documents have been described below.