M.D M.D - 7 months ago 240
HTML Question

Width of R code chunk output in RMarkdown files knitr-ed to html

Question:



What is the current working solution to set the width of r code output in html files? I would like to set width to something big and use a slider in the html output.

options(width = XXX)
seems not to work anymore.

Example:



---
title: "Width test"
output:
html_document:
theme: default
---
```{r global_options, echo = FALSE, include = FALSE}
options(width = 999)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE,
cache = FALSE, tidy = FALSE, size = "small")
```
```{r}
sessionInfo()
```
```{r}
dataM <- matrix(rnorm(100, 5, 2), ncol = 15)
dataM
```


Result:



enter image description here

sessionInfo() output on the screenshot above.

Related:



(
options(width = 999)
is not working for me)

knitr: How to prevent text wrapping in output?

How to adjust the output width of RStudio Markdown output (to HTML)

Answer

You can use this to make the pre blocks scroll horizontally if it overflows.

---
title: "Width test"
output:
  html_document:
    theme: default
---

<style>
pre {
  overflow-x: auto;
}
pre code {
  word-wrap: normal;
  white-space: pre;
}
</style>

```{r global_options, echo = FALSE, include = FALSE}
options(width = 999)
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE,
                      cache = FALSE, tidy = FALSE, size = "small")
```
```{r}
sessionInfo()
```
```{r}
dataM <- matrix(rnorm(100, 5, 2), ncol = 20)
dataM
```

enter image description here

Comments