gpt4 book ai didi

html - RMarkdown 文件中 R 代码块输出的宽度 knitr-ed 到 html

转载 作者:太空狗 更新时间:2023-10-29 13:22:09 27 4
gpt4 key购买 nike

问题:

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

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
```

结果:

enter image description here

上面屏幕截图中的 sessionInfo() 输出。

相关:

(options(width = 999) 对我不起作用)

knitr: How to prevent text wrapping in output?

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

最佳答案

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

---
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


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

的容器 div

Similar question/answer

---
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>

enter image description here

关于html - RMarkdown 文件中 R 代码块输出的宽度 knitr-ed 到 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36845178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com