【发布时间】:2018-10-24 09:32:56
【问题描述】:
我正在使用包含数据表的 R 降价生成报告。我希望生成的 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 选项。如果表格超出了你设置的宽度,你会得到一个滚动条,如果数据仍然合适,那么你不会。 -
hmmm...我已经添加了这一行,并且表格仍然是页面的宽度,没有添加滚动条并且我的页面上没有边距