Reputation: 483
I need to know how to source a CSS file to be applied to my .Rmd report, using a chunk in RMarkdown? Is it possible?
Actually, I would like to make .css
file become a parameter.
Something like this below:
---
title: "Untitled"
output:
html_document
---
```{css, echo=FALSE}
source('style.css')
```
Upvotes: 2
Views: 587
Reputation: 3636
You can use a css chunk with the code
chunk option (which is intended to allow for programmatically inserted code)
---
title: "Untitled"
output: html_document
params:
my_css: my_css.css
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{css, code = readLines(params$my_css)}
```
Hello World!
Upvotes: 4
Reputation: 8676
You could try using htmltools::includeCSS()
:
Contents of my_css.css
:
p {
color: red;
}
Contents of Rmd:
---
title: "Untitled"
output: html_document
params:
my_css: my_css.css
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r}
htmltools::includeCSS(params$my_css)
```
Hello World!
Produces red text:
Upvotes: 4