R markdown PDF:为测验者暂时隐藏剧透代码 [英] R markdown PDF: Temporarily hide spoiler code for quiz takers

查看:89
本文介绍了R markdown PDF:为测验者暂时隐藏剧透代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用R降价创建PDF R课程.我想插入如下测验:

I am using R markdown to create a PDF R course. I want to insert a quiz like the following:

---
output: pdf_document
---

What is the class of the following R object?

1. `pi`

```{r}
class(pi)
```

与预期的一样,将创建具有以下内容的PDF:

Which, as expected, creates a PDF with this content:

但是,我希望读者不能如此轻松地获得答案.这些是迄今为止我实现这一目标的想法:

However, I would like the reader to not have such an easy access to the answer. These are the ideas I've had so far to achieve this:

  1. 将答案涂成白色,并用白色编码,因此读者必须选择文本才能看到答案;
  2. 包括一个可以将鼠标悬停在问题上的工具提示.
  3. 将答案整理到文档末尾;
  4. 以较小的字体将答案上下颠倒;
  5. 使用类似于stackoverflow的>!代码的方式隐藏剧透(不过,不知道R markdown是否具有这样的功能);
  1. Paint the answer and code white, so the reader would have to select the text to see the answer;
  2. Include a tooltip that would work on mouse over question.
  3. Flush the answer to the end of the document;
  4. Setting the answer upside down, in a smaller font;
  5. Use something similar to the >! code of stackoverflow to hide spoilers (no idea if there is such a feature on R markdown, though);

对我来说,第三个想法似乎是执行此操作的最优雅的方法,但我不知道如何实现它.我看过如何在RMarkdown中隐藏代码以及选择查看代码的方法 http://yihui.name/knitr/options/

To me, the third idea seems like the most elegant way to do this, but I don't know how to implement it. I've taken a look at How to hide code in RMarkdown, with option to see it, http://yihui.name/knitr/options/ and https://www.ctan.org/pkg/exam?lang=en, but found nothing I could use.

如您所见,我不介意该解决方案是否要求用户在计算机上阅读文档,但是如果我能找到一种适用于文档打印版本的解决方案,那就太好了.

As you can see, I don't mind if the solution requires the user to read the document on a computer, but if I can find a solution that would also work on printed versions of the document, that would be great.

推荐答案

我不是在考虑一个完整的闪亮应用程序,而是类似.Rmd

I wasn't thinking of a full shiny app, but something like this .Rmd

---
output: html_document
---

## q1 what is `class(pi)?`

<div id="spoiler" style="display:none">

```{r}
class(pi)
```

</div>

<button title="Click to show answer" type="button"
   onclick="if(document.getElementById('spoiler') .style.display=='none')
              {document.getElementById('spoiler') .style.display=''}
            else{document.getElementById('spoiler') .style.display='none'}">
  Show/hide
</button>

然后单击

这篇关于R markdown PDF:为测验者暂时隐藏剧透代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆