Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a solution chunk as a chained setup chunk hides the solution in the UI #548

Open
gadenbuie opened this issue Jun 29, 2021 · 2 comments
Assignees
Labels
effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code
Projects

Comments

@gadenbuie
Copy link
Member

In the example below, the second exercise uses the solution to the first exercise as its setup chunk, via the chunk option exercise.setup = "first-solution". As a result, the Solution button is not included in the UI since the solution code isn't added to the HTML.

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

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

## Topic 1

```{r first, exercise = TRUE}
x <- 1
x + 1
```

```{r first-solution}
x <- 2
x + 1
```

```{r second, exercise = TRUE, exercise.setup="first-solution"}
x + 2
```

```{r second-solution}
x + 2
```

The HTML output for the first exercise in the above is missing the code for the solution.

<div class="tutorial-exercise" data-label="first" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">
<pre class="text"><code>x &lt;- 1
x + 1</code></pre>
<script type="application/json" data-ui-opts="1">{"engine":"r","has_checker":false,"caption":"<span data-i18n=\"text.enginecap\" data-i18n-opts=\"{&quot;engine&quot;:&quot;R&quot;}\">R Code<\/span>"}</script>
</div>
<div class="tutorial-exercise-support" data-label="first-solution" data-completion="1" data-diagnostics="1" data-startover="1" data-lines="0">

</div>

The problem doesn't occur if a new chunk is created duplicating the solution chunk:

```{r first-solution2, ref.label="first-solution"}

```

```{r second, exercise = TRUE, exercise.setup="first-solution2"}
x + 2
```
@gadenbuie
Copy link
Member Author

I think the solution here is to remove the complexity around the knitr hooks. Instead of individually writing the tutorial support chunks, we should have the exercise chunk write all of the HTML for the exercise and then we'll disable any kind of output from the support chunks. In addition to simplifying the logic, this would let us re-use chunks between exercises.

Alternatively, if we decouple hints and solutions and let the shiny app control whether the solution button is present (and what that solution is), then we wouldn't even need to write the solution chunk html into the document.

@gadenbuie gadenbuie added effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code labels Aug 26, 2021
@gadenbuie gadenbuie added this to Backlog in v0.11.0 Jan 19, 2022
@luk-brue
Copy link

I really appreciate that you are working on this, because in the context of chained setup chunks, it would avoid unnecessary duplication of a solution. My current strategy for the tutorials I am working on (GitHub repo) is to duplicate the solution chunk and make it a chained setup chunk for the next exercise. So currently I need:

  • a chained setup chunk for the next exercise building on the solution
  • a user-viewable solution chunk

Good news might be, that it might probably be possible to address the issue without breaking old tutorials, because the duplication strategy is not broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: medium < 3 days of work priority: medium Could be fixed before next release type: bug Maintainers have validated that it is a real bug in the project code
Projects
v0.11.0
Backlog
Development

No branches or pull requests

2 participants