RMarkdown文件中R代码块输出的宽度编织为html

m-d*_*-dz 9 html css r knitr r-markdown

题:

在html文件中设置r代码输出宽度的当前工作解决方案是什么?我想将宽度设置为大的并在html输出中使用滑块.

options(width = XXX) 似乎不再工作了.

例:

---
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
```
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

sessionInfo()输出在上面的截图中.

有关:

(options(width = 999)不适合我)

knitr:如何防止输出中的文本换行?

如何调整RStudio Markdown输出的输出宽度(到HTML)

raw*_*awr 15

如果pre块溢出,您可以使用它来使块水平滚动.

---
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
```
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


对于可滚动高度,创建一个具有最大高度和一个overflow-y: auto;或的容器divoverflow-y: scroll;

类似的问题/答案

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

<style>
.pre-scrolly {
  max-height: 150px;
  overflow-y: auto;
}
</style>

<div class='pre-scrolly'>
```{r}
sessionInfo()
```
</div>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


luk*_*keA 5

您可以重置widthmax-width使用自定义 CSS,例如:

---
title: "Width test"
output:
  html_document:
    theme: default
---
<style>
.main-container { width: 1200px; max-width:2800px;}
</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 = 15)
dataM
```
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明