编织到html的RMarkdown文件中R代码块输出的宽度 [英] Width of R code chunk output in RMarkdown files knitr-ed to html

查看:307
本文介绍了编织到html的RMarkdown文件中R代码块输出的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:



在html文件中设置r代码输出宽度的当前可行解决方案是什么?我想将宽度设置为较大的值,并在html输出中使用滑块。



options(width = XXX)似乎不再起作用。



示例:



 - -
标题:宽度测试
输出:
html_document:
主题:默认
---
```{r global_options,echo = FALSE,include = FALSE}
选项(宽度= 999)
knitr :: opts_chunk $ set(echo = FALSE,警告= FALSE,消息= FALSE,
缓存= FALSE,整洁= FALSE,大小=小)
```
```{r}
sessionInfo()
```
```{r}
dataM<-matrix(rnorm(100,5,2),ncol = 15)
dataM
```



结果:





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



相关:



选项(宽度= 999)对我不起作用)








要获得可滚动的高度,请创建一个容器高度为div且最大高度为 overflow-y:auto; overflow-y:滚动;




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:

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)

解决方案

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


For a scrollable height, create a container div with a max height and a overflow-y: auto; or overflow-y: scroll;

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>

这篇关于编织到html的RMarkdown文件中R代码块输出的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆