Any data analysis report can be more interesting with interactive charts and tables. Readers enjoy being able to ask questions of the data themselves to confirm your conclusions. You can add interactivity to your analyses by using Plotly. Plotly is a powerful software tool that enables you to make amazing charts with R.

My first thought after playing around with the library was wondering if I could use it when sharing to my website. My site is hosted on Github and powered by Jekyll. You can see the repo here. I usually knit my blog posts to a markdown file but that doesn't work with Plotly- the charts don't show up in the post. I searched for step-by-step instructions on how to make it work and came up empty handed. I did find this post which pointed me in the right direction but it took a little editing from there. Here is what I learned.

How to Build a Blog Post with Plotly from an .RMD for Your Github Hosted Blog

  1. Starting with the post itself, you'll have to write with html tags instead of using markdown. For me, that consisted of using <h3> instead of ### for headers and <ul> and <li> for lists. It's an inconvenience but it shouldn't stop you from writing your post.
  2. Add this line to your YAML front-matter: htmlwidgets: TRUE. By the end of this post you'll understand why this is neccessary but the short version is you'll use this switch to indicate if your post includes Plotly. Loading the page will probably take longer than a regular page so using this switch means we'll only have the delay when necessary.
  3. Edit your _layouts/post.html file to include this code snippet. This checks for the htmlwidgets switch from the previous step and if its found, builds in a link to all of the dependency files. I call them dependency files because they are Javascript libraries that power Plotly charts- your site now depends on these library files. Without them you'll only see a blank space in your blog.
  4. ```r plot_ly(x= mpg, y= disp, data= mtcars, mode="markers") ```