使用learnr创建开放式问题:r中的教程

使用learnr创建开放式问题:r中的教程,r,shiny,r-markdown,learnr,R,Shiny,R Markdown,Learnr,我希望允许学生在每次测验开始时输入学生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 =

我希望允许学生在每次测验开始时输入学生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
)

我检查了3位数字,它工作了新的问题是运行文档需要很长的时间(到目前为止已经25分钟)。有没有加快运行速度的建议?

您可以使用
shinyFeedback
和服务器chunck输入学生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")
    }
    
  })


我最终使用了classis learnr
问题文本

```{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
  )
))
```
```{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
  )
))
```
`{r student\u id,echo=FALSE}

id_matrix@Maral Dorri,在回答您发布的其他问题之前,我想知道上述解决方案是否有效。谢谢你的反馈。谢谢Waldi,我确实收到了这个框,但我不知道如何添加提交按钮,以便我可以记录他们输入的答案。我目前正在使用
new_recorder录制提交的答案。您可以在
observeEvent
else
部分调用
new_recorder(…)
。感谢您的回复,但我不确定如何将此添加到输入的数字。新的_记录器应记录任何事件。但是,由于没有提交选项,因此它没有记录学生ID的输入值。如果您是对的,则每次达到7位数字时都会写入save.txt,而不要求提交。然而,在else部分,当learnr在shinny上工作时,可能会显示一个提交按钮:这超出了这个问题的范围,但是是可行的。