From the course: R: Interactive Visualizations with htmlwidgets

What are htmlwidgets? - R Tutorial

From the course: R: Interactive Visualizations with htmlwidgets

Start my 1-month free trial

What are htmlwidgets?

- [Instructor] What is htmlwidgets? Well, htmlwidgets is two things simultaneously. It's a framework for allows all developers to easily create bindings between JavaScript and R, and it's also a collection of R packages that allow you, as users of R, to build interactive charts, plots, maps, interactive tables and much more directly from within RStudio. This course is focused entirely on how to use these htmlwidgets to build interactive visualizations of your own data but I think it's really important for you to understand for if you wanted to, you could build your own htmlwidget library or contribute to the existing htmlwidget library development. So, let's quickly run over both sides of htmlwidgets, the framework for creating our packages and the very basics of what we can output from RStudio using htmlwidgets. First off, why is it interesting to have the framework for bringing JavaScript to R? Well, the reason is for JavaScript is the interactive web. Most of the interactive things that you see in websites are provided by JavaScript. For instance, the browser-based maps provided by Google, Bing and Apple. And data journalism sites like FiveThirtyEight dot com inflowing data use JavaScript to build rich, interactive visualizations. This is exactly the kind of things that we'd love to be able to do inside of R and is what htmlwidgets provides us. Now, building visualizations from scratch with JavaScript, over populate the free library requires a fairly significant amount of effort and quite a deep understanding of how browsers work which isn't what we're interested in as R users. Thankfully, there are many popular JavaScript libraries designed to make it as easy as possible to build these visualizations. For instance, plotly and highcharter for a whole host of different types of jobs. Leaflet for creating interactive maps including choropleth and vis.js that is extremely powerful for visualizing networks and creating timelines. The htmlwidget's framework is designed and developed by RStudio, who have committed to significant resources to making it as powerful and as fully-featured as possible. Because it's designed by our studio, it's a technology that works best if you develop your visualizations within the RStudio application. It doesn't really suite working in the console. So how about these htmlwidget packages? Well, they're pretty normal packages. Most of them are available directly from CRAN and typically, a htmlwidget package binds to just one JavaScript library. For instance, highcharter allows us to build high charts JavaScript visualizations in R. Leaflet is the library that let's us build interactive maps using leaflet JS. Plotly is the library that allows us to use the plotly js library for building interactive charts. Because each htmlwidget library binds to a separate JavaScript library, htmlwidget packages are pretty much completely different beasts to one another. Learning how to build charts with highcharter does not mean you'll be able to instantly recreate the chart using the plotly library though it definitely some common lessons, for instance, most good htmlwidgets are designed to work with a pipe operator and expect tiding or long formatted data. Fortunately, this course covers both the similarities and differences between a wide range of different htmlwidget libraries.

Contents