我有下面的代码和4个正确的答案。我要学生们把所有的四个都输入。而不是定义24个排列的答案,我想要4个字段框,将只接受一个答案一次。
question_text(
"Input all paths:",
answer("ABEF", correct = TRUE),
answer("ABCDG", correct = TRUE),
answer("ABCDEF",correct = TRUE),
answer("ABDEF", correct = TRUE),
incorrect = "Direction from top to bottom of the plate",
allow_retry = TRUE,
trim = TRUE
)编辑
我尝试过这种方法,但我认为我不能将答案设置为除单一文本之外的任何其他内容:
library(gtools)
pat <- permutations(4, 4, c("ABEF","ABCDG","ABCDEF","ABDEF"))
question_text(
"Input all possible rupture paths:",
answer(pat, correct = TRUE),
allow_retry = TRUE,
trim = TRUE
)即使我设置了pat <- c("ABEF","ABCDG","ABCDEF","ABDEF"),它也不能成功运行。如何能够同时定义多个答案,而不需要写出它们。
发布于 2020-09-16 14:28:43
我不确定您想要的输出-但是,请检查以下。
指的是:
如何能够同时定义多个答案,而不需要写出它们。
您可以使用lapply创建答案,使用do.call将不同的参数传递给question_text
library(learnr)
do.call(question_text, c(
list("Input all paths:"),
lapply(c("ABEF", "ABCDG", "ABCDEF", "ABDEF"), answer, correct = TRUE),
list(
incorrect = "Direction from top to bottom of the plate",
allow_retry = TRUE,
trim = TRUE
)
))作为*.Rmd文件:
---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}图书馆(Learnr)
Knitr::opts_chunk$set(回声=假)
```{r two-plus-two, exercise=FALSE}do.call(question_text,c)
列表(“输入所有路径:”),
适用(c(“ABEF”,"ABCDG","ABCDEF","ABDEF"),答案,正确=真
名单(
incorrect = "Direction from top to bottom of the plate",allow_retry = TRUE,trim = TRUE)
))

关于:
我想要4个只接受一次答案的字段框。
编辑:添加了一个事件处理程序来访问用户提供的答案。
---
title: "Tutorial"
output: learnr::tutorial
runtime: shiny_prerendered
---
```{r setup, include=FALSE}图书馆(Learnr)
Knitr::opts_chunk$set(回声=假)
问题<-
应用程序(
FUN = question_text,lapply(c("ABEF", "ABCDG", "ABCDEF", "ABDEF"), answer, correct = TRUE),text = paste("Question", 1:4),incorrect = paste("Incorrect", 1:4),MoreArgs = list(allow_retry = TRUE, trim = TRUE),SIMPLIFY = FALSE)
```{r q1, echo = FALSE}Do.call(测验,c(列表(标题=“测验1"),问题))
```{r context="server-start"}event_register_handler("question_submission",函数(会话、事件、数据){
姓名(数据):
“标注”“问题”“回答”“正确”
消息(“事件: question_submission:",数据$答案)
})

https://stackoverflow.com/questions/63867936
复制相似问题