A framework to create bootstrap styled HTML reports from knitr Rmarkdown.
- Uses bootstrap 3.0, should work for all screen sizes.
- Images are automatically centered, thumbnailed and lightboxed using magnific popup.
- Style with themes from bootswatch.
- Code blocks automatically highlighted using highlight.js.
- Code/Output block visibility can be toggled with a mouse click
- Code blocks can be referenced in the text via their labels.
- 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.
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')
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.
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"
output:
knitrBootstrap::bootstrap_document:
toc: true
theme: amelia
highlight: sunburst
---
Named chunks can be referenced in the text with their label. Using
the usual markdown syntax for links. A chunk with label label
would be referenced as [link text](#label)
.
Figures with captions get an additional anchor. This can be linked
using the chunk label with a fig: prefix (or whathever the chunk option
fig.lp is set to). Therefore a figure generated by a code chunk
that produces a single plot and has the fig.cap option set can be linked to
in the text as [Figure N](#fig:label)
.
You can also simply call the render function by itself.
library(knitrBootstrap)
library(rmarkdown)
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()
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>
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
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.
bootstrap.thumbnail
- (TRUE
) - Thumbnail and lightbox images.bootstrap.thumbnail.size
- ('col-md-6'
) - Thumbnail size in bootstrap columns. (see Bootstrap Grid System)bootstrap.type
- ('simple'
) - Type of label for code blocks. ('simple'
,'panel'
,'button'
)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.
- 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