【问题标题】:R: Change width of entire datatable in RmdR:在 Rmd 中更改整个数据表的宽度
【发布时间】: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...我已经添加了这一行,并且表格仍然是页面的宽度,没有添加滚动条并且我的页面上没有边距

标签: css r datatable resize


【解决方案1】:

想要什么

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

工作?

【讨论】:

    猜你喜欢
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多