Skip to content

Commit

Permalink
add Auswertung to template
Browse files Browse the repository at this point in the history
  • Loading branch information
luk-brue committed Oct 29, 2024
1 parent 4b0baa9 commit 671a507
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions inst/tutorials/template/template.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,59 @@ question_checkbox("Wichtig, für eine neue Frage, brauchen wir einen neuen Codec

## Learnings

So hast du heute abgeschnitten:

```{r context="server"}
# Shiny App um die Anzahl richtig beantworteter Fragen anzuzeigen.
# Funktioniert in jedem Tutorial
shiny::observeEvent(
input$get_score,
{
objs2 = learnr:::get_tutorial_state()
# Number of correct questions
n_correct <-
# Access the $correct sublist item in each list item
lapply(objs2, purrr::pluck, "correct") |>
# make it a vector containing: TRUE and FALSE and NAs
# NA is appearing for list items which don't have
# a $correct subitem
unlist() |>
# Taking the sum of a logical Vector returns the number of TRUEs
sum(na.rm=TRUE)
# Number of total questions
total_questions <-
# 1. Access $type in each list item and make it a vector of types
lapply(objs2, purrr::pluck, "type") |> unlist()
# 2. Count the number of "question" in that vector
total_questions <- total_questions[total_questions == "question"] |>
length()
output$score = shiny::renderText(
paste0(n_correct, " von ", total_questions,
" im gesamten Tutorial beantworteten Fragen waren richtig.")
)
invisible()
}
)
```

```{r score, echo=FALSE}
shiny::br()
shiny::actionButton("get_score", "Auswertung!")
shiny::br()
shiny::br()
shiny::textOutput("score")
shiny::br()
```


## Hash generieren

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!
Expand Down

0 comments on commit 671a507

Please sign in to comment.