1

我已经尝试过使用该print功能:

print(dfSummary(df), method = "render")

还有这里的所有解决方案,但它们似乎不适用于html_documentR Markdown 的输出文件类型。

4

2 回答 2

1

奥拉,伊内斯

答案在提供的链接中。您只需要添加max.tbl.height参数并以像素为单位指定高度:

print(dfSummary(df),
      max.tbl.height = 250,
      method = "render")

这是一个可重现的示例(请参阅# comments提示和技巧):

---
title: "Title"
author: "Author"
date: "26/05/2020"
output: 
  html_document:
    toc: TRUE
    toc_float: TRUE
---

```{r setup, include = FALSE}
library(knitr)
library(summarytools)
knitr::opts_chunk$set(results = "asis")
```

### Adding a scrollbar to dfSummary

```{r summarytools-css, echo = FALSE}
# with summarytools’ CSS we can cancel Bootstrap’s CSS (both are included by default)
# without it odd layout are expected, especially with dfSummary()
st_css(bootstrap = FALSE)
```

```{r dfSummary, echo = FALSE}
print(dfSummary(tobacco, 
                style = "grid",           # set style to “grid”
                valid.col = FALSE,        # drop Valid column if redundant
                graph.magnif = 0.82),     # zoom factor (max = 1) for bar plots and histograms
      headings = FALSE,
      footnote = NA,
      # use maximum table (specified) height (in pixels) and wrap the results in a scrollable window
      max.tbl.height = 300,            
      method = "render")
```

在此处输入图像描述

如果您有兴趣,请查看 Dominic 的小插图- “Recommendations for Using summarytools With Rmarkdown”。

于 2020-05-26T13:52:19.723 回答
0

我可以建议使用包“DT”,如果您绝对需要 dfSummary 我可以再试一次,但需要最少的代码来复制您的示例。DT 具有搜索功能,同时让用户可以控制查看数据时看到的行数。

  ---
  title: "DF summary"
  author: "stackoverflow"
  date: "5/24/2020"
  output: html_document
  ---
  ```{r}
  library(DT)
  datatable(head(mtcars, 30), options = list(
  order = list(list(2, 'asc'), list(4, 'desc'))
  ))
  ```
于 2020-05-24T14:06:38.620 回答