【问题标题】:R summarytools dfSummary not displaying correctly in RMarkdown tabsR summarytools dfSummary 未在 RMarkdown 选项卡中正确显示
【发布时间】:2020-09-15 13:57:40
【问题描述】:

我正在尝试将 2 个 dfSummary 输出放入 RMarkdown 中的选项卡式部分。我想我必须使用 results = 'asis' 才能生成绘图,但是当我使用该选项时,选项卡功能会中断。摘要不是显示在选项卡中,而是显示在文档中。

下面的示例是关于 ToothGrowth 数据集的,显示了我希望解决的问题。

---
title: "test"
output: html_document
---

```{r setup, include = FALSE}
library(summarytools)

st_options(plain.ascii = FALSE               # This is very handy in all Rmd documents
         , style = "rmarkdown"               # This too
         , footnote = NA                     # Avoids footnotes which would clutter the results
         , subtitle.emphasis = FALSE         # This is a setting to experiment with - according to the theme used, it might improve the headings layout
)
           
knitr::opts_chunk$set(results = 'asis')
```

## R Markdown

### {.tabset .tabset-pills}  

#### Numeric Variables  

This section is for numeric variables.  

```{r}
summarytools::dfSummary(ToothGrowth[c('len', 'dose')], style = "grid", graph.magnif = 0.75, valid.col = FALSE, tmp.img.dir = "/tmp")
```

#### Factor Variables  

This section is for factor variables.  

```{r}
summarytools::dfSummary(ToothGrowth[c('supp')], style = "grid", graph.magnif = 0.75, valid.col = FALSE, tmp.img.dir = "/tmp")
```

谢谢!

【问题讨论】:

    标签: r r-markdown summarytools


    【解决方案1】:

    我会尝试这两件事:

    1. 设置headings=FALSE。这将防止## 与选项卡式内容的内部工作方式发生冲突。
    2. 使用# {.tabset .tabset-pills},然后使用## Numeric & ## Factor。这可能是第一个解决方案的可行替代方案,因为它使用的标题级别与 summarytools 不同。

    【讨论】:

    • headings = FALSE 工作!我不知道我是怎么错过的。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多