'knitr' Bootstrap Framework

A framework to create Bootstrap < http://getbootstrap.com/> HTML reports from 'knitr' 'rmarkdown'.


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

Table of Contents

Features

  • 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

Examples

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

Installation

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

library(devtools)
install_github('rstudio/rmarkdown')
install.packages('knitr', repos = c('http://rforge.net', 'http://cran.rstudio.org'),
                 type = 'source')
install_github('jimhester/knitrBootstrap')

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

install.packages('knitrBootstrap')

Usage

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

RStudio

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.

---
output:
  knitrBootstrap::bootstrap_document:
    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.

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

Vim

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()
  update
  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")'
  endif
  call g:SendCmdToR(rcmd)
endfunction
 
"bind RMakeHTML_2 to leader kk
nnoremap <silent> <Leader>kk :call RMakeHTML_2()<CR>

Makefile

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

#standard 
make file.html
 
#with bootstrap style chooser 
make THEME_CHOOSER=TRUE file.html
 
#with code style chooser 
make HIGHLIGHT_CHOOSER=TRUE file.html
 
#with both 
make HIGHLIGHT_CHOOSER=TRUE THEME_CHOOSER=TRUE file.html
 
#standalone 
make file_inline.html

Options

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.
  • bootstrap.menu - (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.
  • bootstrap.show.code - (TRUE) - Code from this chunk starts as shown.
  • bootstrap.show.output - (TRUE) - Output from this chunk starts as shown.
  • bootstrap.show.message - (TRUE) - message from this chunk starts as shown.
  • bootstrap.show.warning - (TRUE) - warning from this chunk starts as shown.
  • bootstrap.show.error - (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

News

knitrBootstap 1.0.1

  • Fix for failing vignette on Solaris due to lack on igraph on that platform.

knitrBootstap 1.0.0

Features

  • rewrote javascript DOM manipulation in R to allow more flexible options
  • Images from code blocks where fig.hold!='hold' are centered
  • Images can be excluded from thumbnails using bootstrap.thumbnail #26
  • Can delimit code blocks using panels or buttons
  • Specify show/hide status per chunk using knitr options. #2

Fixes

  • Explicitly include R hljs highlighting because of a chrome issue with yandex
  • Images are being stacked in current implementation #36

knitrBootstrap 0.9.0

Features

  • Remove tocify dependency
  • Move vignettes to vignettes/ from inst/doc

Fixes

  • #22 Images removed by javascript when echo=FALSE
  • #21 rCharts and knitrBootstrap interaction via results="asis" breaks menu and code toggling
  • #20 show_code=FALSE has different behavior in knit_boostrap() vs knit_bootstrap_md() [broken here]
  • #16 HTML output broken when served over HTTPS

knitrBootstrap 0.8.0

Features

  • Migrate to using Bootstrap 3
  • Remove meny option to style, it did not work well on tablets and phones.
  • Code blocks now in panels
  • Output in panels and split by output type (error, message, normal)
  • Automatically uses render_html and highlight=FALSE, so it does not need to be included.
  • Current style chosen is selected.

Fixes

  • Fix for clicking on default style resets both the code and bootstrap style.
  • Fix for as.is html tables, not putting them in output blocks.

knitrBootstrap 0.7.0

Features

  • use magnific popup to do lightboxes rather than fancybox.
  • option to use offscreen or onscreen table of contents navigation.
  • option to set thumbnail size.
  • option to show/hide code blocks by default.

Fixes

Make knitr and R dependencies explicit

knitrBootstrap 0.6.5

  • implement boostrap_html to apply the html header to any arbitrary html file.

knitrBootstrap 0.6.1

  • split knit_bootstrap into two functions, knit_bootstrap_Rmd and knit_bootstrap_md, to put the bootstrap styles around a R markdown and knitted markdown file respectively. This allows knit_bootstrap_md to be used as a drop in replacement for markdownToHTML. Previous behavior of knit_bootstrap function is unchanged.

  • fix #9, wrong url in DESCRIPTION

knitrBootstrap 0.6

  • Use meny to style the table of contents

  • change to using package layout so framework can be bundled as an R package.

  • implement knit_bootstrap function so external makefiles are no longer necessary to change styles or include the style choosers.

  • fix pre code issue with render_markdown in newer versions of knitr

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("knitrBootstrap")

1.0.1 by Jim Hester, 9 months ago


https://github.com/jimhester/knitrBootstrap#readme


Report a bug at https://github.com/jimhester/knitrBootstrap/issues


Browse source code at https://github.com/cran/knitrBootstrap


Authors: Jim Hester


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports knitr, rmarkdown, markdown

Suggests testthat, roxygen2, corrplot, ggplot2, igraph, maps, mapproj, maptools, plyr, reshape2, xtable


See at CRAN