• Stars
    star
    459
  • Rank 91,760 (Top 2 %)
  • Language SCSS
  • Created over 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Creating Pretty HTML From R Markdown

Creating Pretty Documents From R Markdown

Have you ever tried to find a lightweight yet nice theme for the R Markdown documents, like this page?

Themes for R Markdown

With the powerful rmarkdown package, we could easily create nice HTML document by adding some meta information in the header, for example

---
title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  rmarkdown::html_document:
    theme: lumen
---

The html_document engine uses the Bootswatch theme library to support different styles of the document. This is a quick and easy way to tune the appearance of your document, yet with the price of a large file size (> 700KB) since the whole Bootstrap library needs to be packed in.

For package vignettes, we can use the html_vignette engine to generate a more lightweight HTML file that is meant to minimize the package size, but the output HTML is less stylish than the html_document ones.

So can we do BOTH, a lightweight yet nice-looking theme for R Markdown?

The prettydoc Engine

The answer is YES! (At least towards that direction)

The prettydoc package provides an alternative engine, html_pretty, to knit your R Markdown document into pretty HTML pages. Its usage is extremely easy: simply replace the rmarkdown::html_document or rmarkdown::html_vignette output engine by prettydoc::html_pretty in your R Markdown header, and use one of the built-in themes and syntax highlighters. For example

---
title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
---

You can also create documents from prettydoc templates in RStudio.

Step 1: Click the "New File" button and choose "R Markdown".

Step 1

Step 2: In the "From Template" tab, choose one of the built-in templates.

Step 2

Options and Themes

The options for the html_pretty engine are mostly compatible with the default html_document (see the documentation) with a few exceptions:

  1. Currently the theme option can take the following values. More themes will be added in the future.
    • cayman: Modified from the Cayman theme.
    • tactile: Modified from the Tactile theme.
    • architect: Modified from the Architect theme.
    • leonids: Modified from the Leonids theme.
    • hpstr: Modified from the HPSTR theme.
  2. The highlight option takes value from github and vignette.
  3. A new math parameter to choose between mathjax and katex for rendering math expressions. The katex option supports offline display when there is no internet connection.
  4. Options code_folding, code_download and toc_float are not applicable.

Offline Math Expressions

By default, html_pretty uses MathJax to render math expressions. However, using MathJax requires an internet connection. If you need to create documents that can show math expressions offline, simply add one line math: katex to the document metadata:

---
title: Nineteen Years Later
author: Harry Potter
date: July 31, 2016
output:
  prettydoc::html_pretty:
    theme: cayman
    highlight: github
    math: katex
---

This option will enable KaTeX for rendering the math expressions, and all resource files will be included in for offline viewing. The offline document will be ~800k larger.

Related Projects

  • tufte provides the Tufte style for R Markdown documents.
  • BiocStyle provides standard formatting styles for Bioconductor PDF and HTML documents.
  • rmdformats by Julien Barnier contains HTML formats and templates for R Markdown documents, with some extra features such as automatic table of contents, lightboxed figures, and dynamic crosstab helper.
  • markdowntemplates by Bob Rudis is a collection of alternative R Markdown templates.
  • prettyjekyll by Florian Privé uses prettydoc to convert R Markdown documents to Jekyll Markdown for blog posting.

Gallery

Here are some screenshots of the HTML pages generated by prettydoc with different themes and syntax highlighters.

Cayman (demo page)

Cayman Theme

Tactile (demo page)

Tactile Theme

Architect (demo page)

Architect Theme

Leonids (demo page)

Leonids Theme

HPSTR (demo page)

HPSTR Theme

More Repositories

1

spectra

A header-only C++ library for large scale eigenvalue problems
C++
704
star
2

LBFGSpp

A header-only C++ library for L-BFGS and L-BFGS-B algorithms
C++
493
star
3

showtext

Using Fonts More Easily in R Graphs
C
466
star
4

MiniDNN

A header-only C++ library for deep neural networks
C++
374
star
5

recosystem

Recommender System Using Parallel Matrix Factorization
C++
85
star
6

RSpectra

R Interface to the Spectra Library for Large Scale Eigenvalue and SVD Problems
C++
77
star
7

ADMM

Solving Statistical Optimization Problems Using the ADMM Algorithm
C++
74
star
8

RcppNumerical

Rcpp Integration for Numerical Computing Libraries
C++
55
star
9

rARPACK

Solvers for Large Scale Eigenvalue and SVD Problems
R
45
star
10

tinydnn

Tiny yet Powerful Deep Neural Networks
C++
42
star
11

conan-danmu

《名侦探柯南》B站弹幕浏览器
R
38
star
12

ADMM-Spark

Implementation of ADMM algorithm on Apache Spark
Scala
24
star
13

fontr

Extracting Glyphs From Font Files
C++
23
star
14

sysfonts

Loading Fonts into R
R
22
star
15

arpack-eigen

A header-only C++ redesign of ARPACK using the Eigen library
C++
21
star
16

fastncdf

Fast Computation of Normal CDF
C
18
star
17

almond

ALMOND: Adaptive Latent Modeling and Optimization via Neural Networks and Langevin Diffusion
Python
12
star
18

COS-article

统计之都主站 (http://cos.name/) 文章相关代码
HTML
10
star
19

parallel-translation

Chinese translation of the vignette of "parallel" package
10
star
20

hugo-blog-en

My English blog built with Hugo
HTML
10
star
21

arpack-arma

A header-only C++ redesign of ARPACK using the Armadillo library
C++
9
star
22

temperflow

Efficient Multimodal Sampling via Tempered Distribution Flow
Python
9
star
23

rcpp-note

Rcpp API reference
HTML
8
star
24

cdtau

Unbiased Contrastive Divergence Algorithm
C++
8
star
25

Rmath-Java

Java wrapper of Rmath library for statistical distribution functions
C
7
star
26

miniGPU

A Minimal Example of Using OpenCL in R Packages
C
5
star
27

markerpen

Marker Gene Detection via Penalized Principal Component Analysis
C++
5
star
28

fontemoji

Plotting Emojis in R Graphs
R
5
star
29

Science

Master of Science
4
star
30

clplite

High Performance Linear Programming Solver Based on Clp
C++
3
star
31

Layer

An R Graphics Device with Layer Support
Shell
3
star
32

R2SWF

Convert R Graphics to SWF (Flash)
C
3
star
33

cutest-lbfgs

Testing and benchmarking L-BFGS/L-BFGS-B solvers with CUTEst
C++
3
star
34

R2SWF-archive

Convert R Graphics to SWF (Flash)
C
3
star
35

cleveland-r-meetup

Slides and code for the presentation given at the Greater Cleveland R Group
R
2
star
36

fdaplus

Enhancement of the 'fda' package for functional data analysis
C
2
star
37

en

My (old) English blog. New one at https://github.com/yixuan/hugo-blog-en
HTML
2
star
38

gradfps

Gradient-based Fantope projection and selection algorithm for sparse PCA
C
2
star
39

bigspline

Smoothing Spline on Spark
Scala
1
star
40

test

R
1
star
41

cn

My Chinese Blog
CSS
1
star
42

Algorithms

A place to hold code snippets of algorithms
C++
1
star
43

yixuan.github.com

My homepage
HTML
1
star
44

rationalfun

An R package to manipulate rational functions
R
1
star