简体   繁体   English

如何在 R 的 distill 文章中添加代码折叠到 paged_table 和 kable 输出

[英]How to add code folding to paged_table and kable outputs in distill article in R

Thanks to Martin Schmelzer we have a wonderful solution to hide/show outputs from code chunks in R markdown HTML documents.感谢Martin Schmelzer ,我们有一个绝妙的解决方案来隐藏/显示 R markdown HTML 文档中代码块的输出。 It also works well with distill articles made from the distill package in R.它也适用于由 R 中的distill package 制成的蒸馏制品。 I was hoping if it could be extended to hide/show paged_table (from Rmarkdown package) and kable (from knitr package) outputs as well.我希望它是否可以扩展到隐藏/显示 paged_table(来自Rmarkdown包)和 kable(来自knitr包)输出。 I know that something has to be added to the javascript to include classes related to paged_table and kable outputs but I don't know to write javascript codes.我知道必须在 javascript 中添加一些内容以包含与 paged_table 和 kable 输出相关的类,但我不知道要编写 javascript 代码。 Is it possible to do so in the first place?有可能一开始就这样做吗? Thanks.谢谢。

title: "Untitled"
description: |
  A new article created using the Distill format.
author:
  - name: Nora Jones 
    url: https://example.com/norajones
    affiliation: Spacely Sprockets
    affiliation_url: https://example.com/spacelysprokets
date: "`r Sys.Date()`"
output: distill::distill_article
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

#paged_table output which I want to hide/show like code folding
```{r}
rmarkdown::paged_table(iris)
```

#kable output which I want to hide/show like code folding
```{r}
knitr::kable(iris)
```

Do you mean something like this?你的意思是这样的吗?

title: "Untitled"
description: |
  A new article created using the Distill format.
author:
   - name: Nora Jones 
    url: https://example.com/norajones
    affiliation: Spacely Sprockets
    affiliation_url: https://example.com/spacelysprokets
date: "`r Sys.Date()`"
output: distill::distill_article
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

#paged_table output which I want to hide/show like code folding
```{r}
rmarkdown::paged_table(iris)
```

#kable output which I want to hide/show like code folding
<button class="btn btn-primary" data-toggle="collapse" data-target="#BlockName">     Show/Hide </button>  
<div id="BlockName" class="collapse">  
```{r}
knitr::kable(iris)
```
</div>

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM