如何在Rmd中更改整个datatable的宽度

5

我正在使用R Markdown生成一份报告,其中包含一个数据表格。我希望生成的html保持一些边距,而不是让表格占据整个页面宽度。

我尝试了包括以下内容:

knitr::opts_chunk$set(fig.width=5, fig.height=8) 

我尝试过这个:

 ``` {r fig1, fig.height = 3, fig.width = 5, echo = FALSE, include=TRUE}

我尝试在输出的头部定义图像大小,也尝试在数据表本身的列宽选项上进行调整。

有什么建议吗?

这是一个Rmd示例:

---
title: "Initial Data Check Report"
date: "`r format(Sys.time(), '%B %d, %Y %H:%M:%S', 'America/Chicago', T)`"
output:
  html_document:
    self_contained: yes
    theme: null
    highlight: null
    mathjax: null
params:
  client: "ClientName"

---

### Audit Table
Some text here

---

```{r table, echo = FALSE, include=FALSE}
library(dplyr)
library(DT)
data = mtcars

```

``` {r fig1, fig.height = 3, fig.width = 5, echo = FALSE, include=TRUE}
datatable(data)

```

例如,您可以使用datatable(data, options = list(scrollX = '300px'))。查找scrollX选项。如果表格溢出您设置的宽度,则会出现滚动条,否则不会。 - Lodewic Van Twillert
嗯...我已经添加了这一行,但表格仍然是页面的宽度,没有滚动条,页面上也没有边距。 - SarahGC
1个回答

9

Would something like

<div style = "width:80%; height:auto; margin: auto;">
``` {r fig1, echo = FALSE, include=TRUE}
datatable(data)
```
</div>

工作?


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接