Skip to content

Commit 671a507

Browse files
committed
add Auswertung to template
1 parent 4b0baa9 commit 671a507

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

inst/tutorials/template/template.Rmd

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,59 @@ question_checkbox("Wichtig, für eine neue Frage, brauchen wir einen neuen Codec
433433

434434
## Learnings
435435

436+
So hast du heute abgeschnitten:
437+
438+
```{r context="server"}
439+
# Shiny App um die Anzahl richtig beantworteter Fragen anzuzeigen.
440+
# Funktioniert in jedem Tutorial
441+
442+
shiny::observeEvent(
443+
input$get_score,
444+
{
445+
objs2 = learnr:::get_tutorial_state()
446+
447+
# Number of correct questions
448+
449+
n_correct <-
450+
# Access the $correct sublist item in each list item
451+
lapply(objs2, purrr::pluck, "correct") |>
452+
# make it a vector containing: TRUE and FALSE and NAs
453+
# NA is appearing for list items which don't have
454+
# a $correct subitem
455+
unlist() |>
456+
# Taking the sum of a logical Vector returns the number of TRUEs
457+
sum(na.rm=TRUE)
458+
459+
# Number of total questions
460+
461+
total_questions <-
462+
# 1. Access $type in each list item and make it a vector of types
463+
lapply(objs2, purrr::pluck, "type") |> unlist()
464+
465+
# 2. Count the number of "question" in that vector
466+
total_questions <- total_questions[total_questions == "question"] |>
467+
length()
468+
469+
470+
output$score = shiny::renderText(
471+
paste0(n_correct, " von ", total_questions,
472+
" im gesamten Tutorial beantworteten Fragen waren richtig.")
473+
)
474+
invisible()
475+
}
476+
)
477+
```
478+
479+
```{r score, echo=FALSE}
480+
shiny::br()
481+
shiny::actionButton("get_score", "Auswertung!")
482+
shiny::br()
483+
shiny::br()
484+
shiny::textOutput("score")
485+
shiny::br()
486+
```
487+
488+
436489
## Hash generieren
437490

438491
Wenn du mit deinen Antworten im Tutorial zufrieden bist, generiere dir deinen Hash-Code, kopiere ihn und lade ihn bei der entsprechenden Abgabe auf Moodle hoch!

0 commit comments

Comments
 (0)