0

这是我的 Rmarkdown 代码:

---
title: "Tutorial"
output:learnr::tutorial:
    code_folding: hide
runtime: shiny_prerendered
---

```{r setup}
library(learnr)
knitr::opts_chunk$set(echo = FALSE)

```


## 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}
library(tidyverse)
mtcars %>% select(cyl, mpg)
```

### 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}
add <- function() {
  
}
```

我已经尝试了所有标识选项,但它不起作用。有什么帮助吗?

4

1 回答 1

1

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

对于 html_doc - 是的。铁:

output:
  html_document:
    code_folding: hide

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

CSS:

<style>
details {
    border: 1px solid;
    border-radius: 10px;
    padding: .1em .5em 0;
    text-align: right;
}
</style>

使用:

<details>
<summary>Show/hide code</summary>
```{r two-plus-two, exercise=TRUE}
library(tidyverse)
mtcars %>% select(cyl, mpg)
```
</details>

输出:

在此处输入图像描述

PS如果您需要对 IE/Edge 的支持 - 看看那里

于 2022-01-07T13:49:26.917 回答