Laura
Laura

Reputation: 483

Why `code_folding: hide` doesnt give the option to hide/show code in Rmarkdown?

This is my Rmarkdown code:

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

I already tried all the identation options , but its not working. Any help?

Upvotes: 0

Views: 923

Answers (1)

manro
manro

Reputation: 3677

As seems, code-folding option doesn't work for output "learnr".

For html_doc - yes. F.e.:

output:
  html_document:
    code_folding: hide

But you can try next solution with details:

CSS:

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

Using:

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

Output:

enter image description here

P.S. If you need a support to IE/Edge - look there

Upvotes: 1

Related Questions