2

我想让学生在每次测验开始时输入他们的学生证。只要输入 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 learnr 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 分钟)。有什么建议可以加快速度吗?

4

2 回答 2

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")
    }
    
  })

在此处输入图像描述

于 2020-09-15T05:29:37.160 回答
0

我最终使用了 classis learnr 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
  )
))
```
于 2020-09-17T15:34:03.373 回答