library(learnr) library(submitr) library(gradethis) library(tidyverse) knitr::opts_chunk$set(echo = FALSE) options(tutorial.storage = "none") knitr::opts_chunk$set(exercise.checker = gradethis::grade_learnr)
The first thing you have to do is to log in.
instructor_key <- "isostats" account_name <- "statprep.annie@gmail.com" credentials <- "password.csv" # "1WvQDD1sQHcc_aZ1eisWkZvhU4a3jEAR2HXt_1REojpM" storage_actions <- in_local_file("submissions.csv")
Click on Next topic to start.
If you'd like users to submit open-ended answers, use a text box question. Correct and incorrect answers will be matched exactly (including white space). A minimum of one correct answer is required.
Text value inputs are trimmed before they are compared to answers provided.
Here a custum question_is_correct
function is used
question_is_correct.always_correct <- function(question, value, ...) { return(learnr::mark_as(TRUE, NULL)) } question( "Provide your answer", answer("answer", correct = TRUE), correct = "Answer Provided", allow_retry = TRUE, type = c("always_correct", "learnr_text") )
If the user has to be able to modify answer, we have to trick learnr, by recording "incorrect" answers. Here is another version allowing this, unfortunately with bright red buttons.
question_text( "Provide your answer", answer("C0rrect", correct = TRUE), incorrect = "Ok", try_again_button = "Modify your answer", allow_retry = TRUE )
question("Which planet do we live on?", answer("Mars", correct=FALSE), answer("Earth", correct = TRUE, message = "Good job Earthling!"), answer("Saturn", correct = FALSE), allow_retry = TRUE, random_answer_order = TRUE )
question_text( "Please enter the word 'C0rrect' below:", answer("correct", message = "Don't forget to capitalize"), answer("c0rrect", message = "Don't forget to capitalize"), answer("Crorrect", message = "Is it really an 'o'?"), answer("C0rrect ", message = "Make sure you do not have a trailing space"), answer("Correct", correct = TRUE), allow_retry = TRUE, trim = FALSE )
grade_result()
grade_result()
checks whether or not the student's code returns the correct result. It matches the result against one or more conditions and returns the message (and correct/incorrect status) associated with the first matched condition.
Here is an example of grade_result()
in use.
grade_result( pass_if(str_length(.result) > 4, "Write some more") )
text_check <- function( label, user_code, solution_code, check_code, envir_result, evaluate_result, envir_prep, ... ) { list(message = "Great job!", correct = TRUE, location = "append") }
If I make this into an embedded video (by prepending the link with "bang!") the event recorder doesn't always work.
question("Are you finished with the exercise?", answer("Yes", correct=TRUE), answer("No", correct=TRUE) )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.