首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么`code_folding:隐藏不允许在Rmarkdown中隐藏/显示代码?

为什么`code_folding:隐藏不允许在Rmarkdown中隐藏/显示代码?
EN

Stack Overflow用户
提问于 2022-01-06 22:38:22
回答 1查看 234关注 0票数 0

这是我的Rmarkdown代码:

代码语言:javascript
复制
---
title: "Tutorial"
output:learnr::tutorial:
    code_folding: hide
runtime: shiny_prerendered
---

```{r setup}

图书馆(Learnr)

Knitr::opts_chunk$set(回声=假)

代码语言:javascript
复制
## Topic 1

### Exercise 

*Here's a simple exercise with an empty code chunk provided for entering the answer.*

Write the R code required to add two plus two:

```{r two-plus-two, exercise=TRUE}

图书馆(Tidyverse)

%>%选择(cyl,mpg)

代码语言:javascript
复制
### Exercise with Code

*Here's an exercise with some prepopulated code as well as `exercise.lines = 5` to provide a bit more initial room to work.*

Now write a function that adds any two numbers and then call it:

```{r add-function, exercise=TRUE, exercise.lines = 5}

添加<- function() {

}

代码语言:javascript
复制

我已经试过了所有的选择,但都没有用。有什么帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2022-01-07 13:49:26

看起来,code-folding选项不适用于output "learnr"

为了html_doc -是的。F.e.:

代码语言:javascript
复制
output:
  html_document:
    code_folding: hide

但是您可以使用details尝试下一个解决方案。

CSS:

代码语言:javascript
复制
<style>
details {
    border: 1px solid;
    border-radius: 10px;
    padding: .1em .5em 0;
    text-align: right;
}
</style>

使用:

代码语言:javascript
复制
<details>
<summary>Show/hide code</summary>
```{r two-plus-two, exercise=TRUE}

图书馆(Tidyverse)

%>%选择(cyl,mpg)

代码语言:javascript
复制
</details>

输出:

P.S.如果您需要对IE/Edge的支持,请看there

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70614465

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档