Skip to content
A framework to create bootstrap styled HTML reports from knitr Rmarkdown.
HTML R Other
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
inst switch mathjax CDN to cdnjs Mar 4, 2019
man Updates for CRAN release Jul 19, 2017
DESCRIPTION Update vignette for ggplot2 release May 24, 2018
NEWS Update vignette for ggplot2 release May 24, 2018 Remove example which no longer is on the bootswatch website May 24, 2018

Knitr Bootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.

Table of Contents


  • Uses bootstrap 3.0, should work for all screen sizes.
  • Automatic table of contents constructed from h1-4 tags.
  • Images are automatically centered, thumbnailed and lightboxed using magnific popup.
  • Style with themes from bootswatch, optionally including a dynamic style switch.
  • Code blocks automatically highlighted using highlight.js, optionally including a dynamic style switch.
  • Code/Output block and plot visibility can be toggled with a mouse click
    • Globally
    • Per language
  • Create completely offline reports, including all css, javascript and images
  • Mathematical equations using mathjax, note this does not work offline


All the examples include a css style switch, so you can try out the various styles from bootswatch.

  • 2d - examples of miscellaneous 2d
  • cars - using ggplot2 and the cars dataset
  • engines - using other language engines
  • illusions - examples of interesting optical illusions
  • maps - examples of map plots, and holding plots until end of the block
  • math - examples of MathJax formulas
  • all - All examples together


If you want to install the latest development version use the devtools package to install the rmarkdown and knitr (devel) prerequisites and this package.

install.packages('knitr', repos = c('', ''),
                 type = 'source')

You can install the latest released version from CRAN. Typically lags behind latest by a good amount.



Knitr Bootstrap includes a knitrBootstrap::bootstrap_document custom rendering function for use with the Rmarkdown package.


Very current versions of RStudio use the render function when you press the "Knit" button. In order to output using knitrBootstrap use the YAML front-matter in your document.

YAML Front-matter

You can also specify the bootstrap_document function as an output type along with the options in the YAML front-matter directly in your Rmd file. All of the global Package Options can be specified in the front matter.

    title: "Test file"
    theme: amelia
    highlight: sunburst
    theme.chooser: TRUE
    highlight.chooser: TRUE

Render Function

You can also simply call the render function by itself.

render('file.Rmd', 'knitrBootstrap::bootstrap_document')


Using the Vim-R-Plugin put the following function in your .vimrc to create the file directly with knitr and the markdown package

function! RMakeHTML_2()
  call RSetWD()
  let filename = expand("%:r:t")
  let rcmd = "require('knitrBootstrap');\
    render(\"" . filename . ".Rmd\", knitrBootstrap::bootstrap_document)"
  if g:vimrplugin_openhtml
    let rcmd = rcmd . '; browseURL("' . filename . '.html")'
  call g:SendCmdToR(rcmd)

"bind RMakeHTML_2 to leader kk
nnoremap <silent> <Leader>kk :call RMakeHTML_2()<CR>


You can use the included Makefile to generate html reports from Rmd files from the command line. If you have a file file.Rmd and you want to create file.html use

make file.html

#with bootstrap style chooser
make THEME_CHOOSER=TRUE file.html

#with code style chooser

#with both

make file_inline.html


Knitr bootstrap extends knitr with a number of additional options. See Knitr Options for more about how to set the two different types of options.

Package Options

  • bootstrap.title - (NULL) Set the title for the html document
  • bootstrap.theme.chooser - (FALSE) - Add a bootstrap style chooser to the page.
  • bootstrap.highlight.chooser - (FALSE) - Add a code style chooser to the page.
  • bootstrap.theme - (Default) - Set the default bootstrap style.
  • bootstrap.highlight - (HighlightJS) - Set the default code style.
  • - (TRUE) - Whether to include the bottom navbar.
  • custom.header - (NULL) - External HTML header contents to include in header block.
  • clean_supporting - (TRUE) - Clean the intermediate supporting documents. (this is only an option for the bootstap_document function)

Chunk Options

  • bootstrap.thumbnail - (TRUE) - Thumbnail and lightbox images.
  • bootstrap.thumbnail.size - ('col-md-6') - Thumbnail size in bootstrap columns. (see Bootstrap Grid System)
  • bootstrap.panel - (FALSE) - Use panels rather than buttons to toggle blocks.
  • - (TRUE) - Code from this chunk starts as shown.
  • - (TRUE) - Output from this chunk starts as shown.
  • - (TRUE) - message from this chunk starts as shown.
  • - (TRUE) - warning from this chunk starts as shown.
  • - (TRUE) - error from this chunk starts as shown.
  • bootstrap.class - ('row') - Bootstrap class to apply to the div containing the chunk.

Bootstrap Themes

Highlight Themes

Highlight Live Test

  • HighlightJs
  • Dark
  • Far
  • Idea
  • Sunburst
  • Zenburn
  • Visual Studio
  • Ascetic
  • Magula
  • Github
  • Google Code
  • Brown Paper
  • School Book
  • IR Black
  • Solarized - Dark
  • Solarized - Light
  • Arta
  • Monokai
  • Xcode
  • Pojoaque
  • Rainbow
  • Tomorrow
  • Tomorrow Night
  • Tomorrow Night Bright
  • Tomorrow Night Blue
  • Tomorrow Night Eighties
You can’t perform that action at this time.