Changing Chunk Background Color in Rmarkdown

RStudio R Markdown Notebook: Change colour of chunk background highlight option in Source panel (not Knitted document)

If I've understood you correctly...

It's possible. I did it with the Viridis theme on Github. On Github, where this theme is found, the authors wrote that you need to have certain things, save the theme in a specific place, all that jazz. I didn't do any of that; I haven't had any problems.

Should you choose to do so, copy the raw script from Viridis.rstheme and use a script editor like Atom or Rstudio. Save the file where you want it and name it exactly as the authors did (it has to match the script's content).

Line 199 is where you go to change the background chunk color for RMarkdown documents. I threw in one of the Viridis purple colors so that the contrast would be vibrant. (I used #481567FF.)

It's bright compared to the original contrast.

Sample Image

Sample Image

change R chunk background color in bookdown gitbook

Thanks to @cderv for pointing me to the right direction. just needed to add !important to the css styles i want to prioritize:

.Rchunk {
background-color: #f2dede !important;
font-weight: bolder;
color: red !important;
}

.Rout {
background-color: #d9edf7 !important;
font-weight: bolder;
color: blue !important;
}

How do I change the entire background color in an RMarkdown HTML Document?

Just add custom CSS to your document. You can place this line at the top (after the yaml part):

1. Inline Style

<body style="background-color:grey;">

2. Embedded Style Sheet

<style>
body { background-color: grey; }
pre, pre:not([class]) { background-color: red; }
</style>

xaringan: Changing code background for specific chunks

This was actually something I was trying to work out a few days ago.

Here's one workaround.

First in your css file or either place the following in xaringan Rmarkdown file:

```{css, echo=F}
.code-bg-red .remark-code, .code-bg-red .remark-code * {
background-color:red!important;
}
```

and then wrap the code chunk like

.code-bg-red[
```{r}
lm(speed ~ dist, cars)
```
]

then your output will be:
red chunk output

You can, of course, change the red to other colors to suit your needs.

How to keep default R markdown colors when knitting to html?

Use highlight: textmate in the YAML header.

For instance,

---
title: "Test"
output:
html_document:
highlight: textmate
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Test

```{r}
library("tidyverse")
```

knits to

result

Further reading

R Markdown: The Definitive Guide



Related Topics



Leave a reply



Submit