我希望允许学生在每次测验开始时输入他们的学生ID。只要输入7位数字,就没有正确答案。这就是我现在所拥有的,但是当定义的答案只有一个文本时,该功能将无法运行。如何接受问题的所有可能条目?
library(gtools)
library(learnr)
id <- permutations(10, 7, c(1,2,3,4,5,6,7,8,9,0))
question_text(
"Enter your student ID",
answer(id, correct = TRUE),
allow_retry = TRUE,
trim = TRUE
)
编辑
我最终使用了classis学习者question_text
:
```{r student_id, echo=FALSE}
id_matrix <- permutations(10, 7, c(1,2,3,4,5,6,7,8,9,0))
id <- apply(id_matrix,1,function(x) paste0(x,collapse = ''))
do.call(question_text, c(
list("Enter your student ID:"),
lapply(id, answer, correct = TRUE),
list(
incorrect = "Your student ID is a 7 digit number on your Husky One Card",
allow_retry = TRUE,
trim = TRUE
)
))
```
我检查了3位数字,它可以工作。 新的问题是运行文档需要很长时间(到目前为止已经需要25分钟)。是否有任何建议可以使文档运行更快?
答案 0 :(得分:1)
您可以使用shinyFeedback
和服务器块来输入学生的ID:
```{r, echo=FALSE}
library(shinyFeedback)
useShinyFeedback()
textInput("id", "Enter your ID")
verbatimTextOutput("value")
```
```{r, context="server"}
observeEvent(input$id, {
if (nchar(input$id) != 7 & !is.na(as.numeric(input$id))) {
showFeedbackWarning(
inputId = "id",
text = "Enter 7 digits"
)
} else {
hideFeedback("id")
}
})
答案 1 :(得分:0)
我最终使用了classis学习者question_text
:
```{r student_id, echo=FALSE}
id_matrix <- permutations(10, 7, c(1,2,3,4,5,6,7,8,9,0))
id <- apply(id_matrix,1,function(x) paste0(x,collapse = ''))
do.call(question_text, c(
list("Enter your student ID:"),
lapply(id, answer, correct = TRUE),
list(
incorrect = "Your student ID is a 7 digit number on your Husky One Card",
allow_retry = TRUE,
trim = TRUE
)
))
```