0

我想在一个块中使用循环来渲染quiz库函数的多个对象。正在编译文件没有问题learnr,但渲染不正确。它正在呈现文本,而不是应该呈现的问题。Rhtml-markdown

这是我的可重现代码,目前无法正确呈现:

---
title: ""
output: learnr::tutorial
runtime: shiny_prerendered
description: ""
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
library(learnr)
```
    
    ```{r, q-part2, echo=FALSE, results='asis'}
    
    words_lst <- structure(list(eng = c("bathroom", "bedroom", "dining room", 
    "door", "house", "kitchen", "garden", "neighbor", "office", "attic", 
    "living room"), nl = c("de badkamer", "de slaapkamer", "de eetkamer", 
    "de deur", "het huis", "de keuken", "de tuin", "de buurman", 
    "het kantoor", "de zolder", "de woonkamer")), row.names = c(NA, 
    -11L), class = "data.frame")
    
    
    for(i in seq_along(words_lst)){
    
     quiz(caption = paste0(i),
           question_text(paste0("Translate: ", words_lst[i,1L]),
           answer("C0rrect ", message = "Make sure you do not have a trailing space"),
           answer(trimws(words_lst[i, 2L]), correct = TRUE),
           incorrect = paste0("Gebruik: ", sub("\\s.*", "", words_lst[i,2L])),
           allow_retry = TRUE,
           trim = TRUE,
           placeholder = "schrijf het juist antwoord"
    ))
    
    }
    
    ```
4

1 回答 1

0

我找到了一个解决方案,事实证明,在一个块中不可能呈现两个或多个函数quiz

我的解决方案是在循环中生成多个question_text,将它们存储在 a 中list,然后使用eval将所有问题作为quiz. 这是解决方案:

    ```{r, q-part1, echo=FALSE, message=FALSE, results="asis"}
    
  words_lst <- structure(list(eng = c("bathroom", "bedroom", "dining room", 
    "door", "house", "kitchen", "garden", "neighbor", "office", "attic", 
    "living room"), nl = c("de badkamer", "de slaapkamer", "de eetkamer", 
    "de deur", "het huis", "de keuken", "de tuin", "de buurman", 
    "het kantoor", "de zolder", "de woonkamer")), row.names = c(NA, 
    -11L), class = "data.frame")


for (j in 1:nrow(words_lst)) {   list_w[[j]] <- question_text(
        paste0("Translate: ", words_lst[j, 1L]),
        answer("C0rrect ", message = "Make sure you do not have a trailing space"),
        answer(trimws(words_lst[j, 2L]), correct = TRUE),
        incorrect = paste0("Gebruik: ", sub("\\s.*", "", words_lst[j, 2L])),
        allow_retry = TRUE,
        trim = TRUE,
        placeholder = "schrijf het juist antwoord"   ) }
    
    
    eval(parse(text = paste0(   "quiz(", paste0("list_w[[",  1:nrow(words_lst), "]]", collapse = ', '), ")" )))
    
    ```
于 2021-05-10T12:33:29.760 回答