Reputation: 333
I am trying to use Knitr to write simple text-only html pages, but the file sizes are extremely large - 700KB for a 1 line RMarkdown. I am on R 3.4.0, and R Studio 1.0.143
For example, the following RMarkdown file generates a 695 kb file. When I look at the source, that is because there is a huge amount of base 64 code under the script tag. Is there anything that can be done to make the file size more compact, say a couple of KBs that I would expect it to be
(eg script src="data:application/x-javascript;base64,LyohIGpRdW...and this goes on and on forever)
---
title: "This is a test"
author: "Mukul Pareek"
date: "June 7, 2017"
output: html_document
---
## This is a test file which when knit to html is 695KB
Upvotes: 8
Views: 2104
Reputation: 126
A more recent approach would be using prettydoc package. Refer to https://github.com/yixuan/prettydoc for more information.
Upvotes: 0
Reputation: 30174
The key to reduce the HTML file size is to set theme: null
, which means to get rid of the giant Twitter Bootstrap styles. Below are a few examples:
---
title: "This is a test"
author: "Mukul Pareek"
date: "June 7, 2017"
output:
html_document:
theme: null
html_vignette: default
prettydoc::html_pretty: default
---
## This is a test file which when knit to html is 695KB
html_document(theme = NULL)
returns a 44kb file; html_vignette
returns 6.1kb; prettydoc::html_pretty
returns 63.7kb (you need to install the prettydoc package). If you want a "flashy" style, I think prettydoc has achieved a great balance between styles and file sizes; otherwise you have to bear with those "vanilla" styles.
Upvotes: 7
Reputation: 4614
My ad-hoc solution is to use the BiocStyle
style from Bioconductor. This reduces the html file size to 50 kb.
---
title: "This is a test"
author: "Mukul Pareek"
date: "June 7, 2017"
output:
BiocStyle::html_document
---
A more extreme solution is found here: How to render HTML from RMarkdown without javascript in output
It produces an html file smaller than 1 kb.
---
title: "This is a test"
author: "Mukul Pareek"
date: "June 7, 2017"
output:
html_document:
theme: null
highlight: null
mathjax: null
---
Upvotes: 4