Stylish reports with Knitr and Bootstrap

I am pleased to announce my project for generating styled, dynamic html reports knitr_bootstrap. Here is an example of a report.

I have been using knitr to produce reports for around 6 months or so now, first using pandoc to generate the html, lately I have been using the Rmarkdown R package instead. This has a couple of advantages over pandoc. First, it is much easier to install as anyone who has tried to install haskell on CentOS can attest to. Secondly, the Rmarkdown package is the same one which is used for Rstudio. While I do not use RStudio much myself, preferring the power of vim, the ease of use and growing ubiquity means that more people can make use of the package.

The only issue with Rmarkdown is the default stylesheet is fairly simplistic, and the table of contents is not as full featured as the one generated by pandoc. I also would prefer to have plots embedded as thumbnails rather than full size, with the option to click on them to zoom. It would also be nice to style the report using [bootstrap], which gives it a much more polished feel.

After a fair amount of work understanding the jQuery framework and [bootstrap], I have gotten the reports feature full enough for others to try. Current features include

  • Automatic table of contents constructed from h1-4 tags using tocify
  • Output automatically resized to fit the display
  • Code/Output block and plot visibility can be toggled with a mouse click
  • Images are automatically thumbnailed and lightboxed using fancybox
  • Code blocks in >50 languages automatically highlighted using highlight.js
  • Automatically wraps code block with div elements to work with bootstrap
  • Can restyle with bootstrap compatible css
  • Completely offline report usiing knitr_bootstrap_standalone.html

It does require a small patch to the Rmarkdown package to work as I am using it, but it should be an fairly easy to accept, and if not workarounds are possible, if less elegant. Please give it a try and let me know your thoughts!

Avatar
Jim Hester
Software Engineer

I’m a Senior Software Engineer at Netflix and R package developer.

Related