SCM

Forum: support

Monitor Forum | Start New Thread Start New Thread
RE: Support for video or audio in questions? [ Reply ]
By: Achim Zeileis on 2025-11-22 06:28
[forum:50125]
Thanks for this, Mayeul!

RE: Support for video or audio in questions? [ Reply ]
By: Mayeul Kauffmann on 2025-11-21 20:26
[forum:50124]
Hi, thanks for these comments! In the first step, I used the moodef package (I like the possibility to define questions in a spreadsheet) to genereate a Moodle XML file (I like the Moodle format, used in the 3 universities where I teach). Then I used the exams package to open the Moodle XML file, and a function to read in it what I needed. This function is here:
https://gricad-gitlab.univ-grenoble-alpes.fr/kauffmma/quizplayr/-/commit/a81b8b5ac0524323e76b9295fdf659c554ca34b7#2ee52544a2a4ef0310701177bd897e0ba8816a9e_155_176
(that is, function read_moodle_questions() of the app.R file of the quizplayr Shiny app).
This was used in Paris in a public event last week, a quizz during a training session with about 12 participants (3 teams).
Image file names and title are stored as markdown in the question string itself, in this way:

The question text....? ![Baez Dylan](Joan_Baez_Bob_Dylan.jpg)

(I've used copyleft images for the examples)

In moodef spreadsheet entry format, if the "answer" field is defined, that is the correct answer (that will be shuffled with wrong answers a_1, a_2...).

If the "answer" field is not defined, then the correct answer is the one starting with the star '*' symbol (in this case, there is no shuffling).


For future reference, I'm reproducing this function below (licence Affero GPL 3).

# Read questions from Moodle XML using the exams package #####################
read_moodle_questions <- function(file) {
# Convert Moodle XML to exams format
exams_quiz <- moodle2exams(file, markup = "markdown")
# Extract questions and related info
questions_data <- list()
for (i in seq_along(exams_quiz)) {
tmp_exams_quiz_file <- tempfile(fileext = ".Rmd")
if (verbose) {cat(i,"\n"); cat(tmp_exams_quiz_file,"\n")}

# Write tmp Rmd file for i-th question;
# TODO: use textConnection()
# Without gsub(), this is saved in .md files: \!\[myimage\](123.png) and then is rendered verbatim as html
# We could remove all backslashes, but the following removes only those that need to:
# gsub( x = "Example, first single-backward slash (\\) kept, image markup converted: \\![myimage\\](121-3.png)",
# pattern = "\\\\!\\[([^\\\\]*)\\\\]\\(([^)]+)\\)", repl="![\\1](\\2)", perl =T ) |> cat()
writeLines(
unlist(exams_quiz[[i]]) |> # gsub("\\\\", '', fixed = TRUE, x=_) # simpler but would remove all backslashes
# FIXME: height=200px, or width=30% work, but not height=20%
# Only fixing the backslashes would be this gsub():
# gsub( pattern = "\\\\!\\[([^\\\\]*)\\\\]\\(([^)]+)\\)", repl="![\\1](\\2)", x=_, perl = TRUE)
gsub( pattern = "\\\\!\\[([^\\\\]*)\\\\]\\(([^)]+)\\)", repl="<br>![\\1](\\2){height=200px}", x=_, perl = TRUE),
tmp_exams_quiz_file)
exam_data <- exams::xexams(tmp_exams_quiz_file)
# Extract the image if any
if (grepl("{height=200px}", x = exam_data$exam1$exercise1$question[1], fixed = TRUE ) ){
question_image <- sub(pattern = "^.+<br>(!\\[[^{]+{height=200px})", repl="\\1",
x = exam_data$exam1$exercise1$question[1], perl = TRUE)
# Remove image from question slot
exam_data$exam1$exercise1$question[1] <- sub(pattern = "<br>!\\[[^{]+{height=200px}", repl="",
x = exam_data$exam1$exercise1$question[1], perl = TRUE)
} else { question_image <- NA }
# FIXME: cannot find, in xexams result, some fields of the xlsx question definition: id, specific feedbacks, tags, and:
# fraction ($exam1$exercise1$metainfo$points is NULL)
# tags ($exam1$exercise1$metainfo$tags is NULL)
# author ($exam1$exercise1$metainfo$author is NULL)
# $exam1$exercise1$metainfo$points is NULL
# part of general feedback seems to be in exam_data$exam1$exercise1$solution: "" "Partially correct." "Incorrect."
# TODO: use $exam1$exercise1$metainfo$shuffle ?
if (exam_data[[1]][[1]]$questionlist[1] == ""){
# We left empty the answer column in moodef .xlsx file, using a_1 a_2... columns; correct one starts with '*' in xlsx file ('\\*' here);
# needed to keep order of possible answers (there is a logical order in proposed answers)
# TODO: add better support to moodef package for this
proposed_answers <- exam_data[[1]][[1]]$questionlist[-1]
correct_answer_number <- grep("^\\\\\\*", proposed_answers)
proposed_answers[correct_answer_number] <- sub(pattern = "^\\\\\\*", replacement = "", x= proposed_answers[correct_answer_number])
shuffleanswers <- FALSE
} else {
# Standard moodef format
proposed_answers <- exam_data[[1]][[1]]$questionlist # Get the list of answers
correct_answer_number <- which(exam_data[[1]][[1]]$metainfo$solution)
# Correct answer should always be the first answer if using standard moodef xlsx format; hence we must shuffle the answers if doing this often
shuffleanswers <- TRUE # In Moodle XML, that would be: <shuffleanswers>true</shuffleanswers>. TODO: add support to moodef for this
}
if (verbose) {cat("Possible answers:\n", proposed_answers,"\nCorrect answer is #", correct_answer_number,"\n")}

questions_data[[length(questions_data) + 1]] <- list(
name = exam_data$exam1$exercise1$metainfo$name,
# FIXME, maybe can be several lines ($exam1$exercise1$question is a vector here, second slot = ""). Do: paste0(..., collaps="<br>") ?
question_text = exam_data[[1]][[1]]$question[1], # Get the question text
question_image = question_image,
answers = proposed_answers,
correct_answer = correct_answer_number,
feedback = ifelse(is.null(exam_data[[1]][[1]]$metainfo$feedback), "", # NULL: no feedback provided
exam_data[[1]][[1]]$metainfo$feedback),
shuffleanswers = shuffleanswers
)
}
return(questions_data)
}

RE: Support for video or audio in questions? [ Reply ]
By: Achim Zeileis on 2025-11-04 01:03
[forum:50113]
Mayeul, thanks for all the details, this looks like a nice project!

Thanks also for the link to "moodef", I wasn't aware of that.

Re: Simple definition via CSV. This makes sense for schoice/mchoice questions with short questions/answers, relatively little formatting, and no randomization beyond simple shuffling. As this is just a subset of the R/exams functionality we never wrote a special interface for this. However, I posted some simple csv2rmd() function in this discussion:

https://r-forge.r-project.org/forum/message.php?msg_id=48195

The "examling" package on GitHub (which unfortunately does not seem to be maintained anymore) generalized this to various other formats:

https://examling.github.io/examling/

Regarding the exchange format: Given that you develop your own functionality, you are not tied to Moodle XML, are you? So you could also use any other format to import questions into quizplayr, couldn't you? For example JSON strings might be an alternative to XML.

If you want to support an interface to input from R/exams exercises you could set up a custom exams2quizplayr() function. Of course, you can also make the function a small wrapper to exams2moodle() with some custom processing. With a separate function you could also decide to process the $solution and $solutionlist elements differently. In principle, these can hold item-specific feedback (which can be leveraged in Moodle).

RE: Support for video or audio in questions? [ Reply ]
By: Mayeul Kauffmann on 2025-11-03 16:36
[forum:50112]
Thank you Achim for these detailed answers!
With respect to:

"What works well here will depend on the system that you use for deploying the exercises"

It will be deployed in an R/Shiny app, whose ui function is here:

https://gricad-gitlab.univ-grenoble-alpes.fr/kauffmma/quizplayr/-/blob/main/app.R?ref_type=heads#L217

A screenshot of the current interface is here:

https://gricad-gitlab.univ-grenoble-alpes.fr/kauffmma/quizplayr#visuals

Currently, for each run, the game host says the question verbally and has to select the number of possible answers (+ or - keys) and the correct answer (by pressing 0 - for 0 red button, or 1 to 4).

I aim to develop a solution that interacts nicely with R packages such as exams and moodef; I've successfully tested the beta app at universities and in (open/public) sessions for adults in (NGO) festivals (in beta: I must read the questions; I cannot show pictures ineternal app as the Shiny app loses the focus). Next public session in Paris on November 15th.

I like the moodef way of creating questions (in a table, in Libre Office Calc); but exports to Moodle xml format (and import with exams) seems to convert the video into a static image (which is heavy/embedded). See my moodef - exams workflow here: https://github.com/josesamos/moodef/issues/17
(The other advantage I see in mooodef over exams is the possibility to have answer-specific feedback (different feedback for different wrong answer); but mooded does not allow to specify an order of answers; those are, so far, side issues to be dealt after my next session).


RE: Support for video or audio in questions? [ Reply ]
By: Achim Zeileis on 2025-11-01 09:21
[forum:50111]

audio.zip (4) downloads
In principle, you can include any static file as a supplement via

invlude_supplement("myname.fil", ...)

See https://www.R-exams.org/templates/Rlogo/ for a worked example with a simple image.

In the same way it is possible to embed audio or video files. Attached is a .zip file containing three .mp3 files and a simple corresponding cloze exercise. (The R code also makes sure that a neutral file name is used for the audio files so that no information about the correct solution is conveyed by the file name.)

There are two possible caveats:

(1) The files can become quite big (especially for video) which can be inconvenient to transfer and import via Base 64 encoded XML files etc. So storing the files elsewhere - be it commercial providers such as YouTube or some solution within university infrastructure (LMS, cloud, etc.) - may be preferable.

(2) For nicer embedding you might want to leverage an audio or video player rather than relying on the browser default. What works well here will depend on the system that you use for deploying the exercises (Moodle, Canvas, standalone HTML, ...). It's possible that you may have to include the HTML code directly (rather than simple Markdown), e.g., via an <iframe> or <video> tag as in the StackOverflow post you linked.

Support for video or audio in questions? [ Reply ]
By: Mayeul Kauffmann on 2025-10-31 13:07
[forum:50110]
Is it possible to include video or audio in questions?

(The video or sound being the main question and/or a hint)

It might depend obviously of what external sytems - Moodle or other -can accept.
Ideally:

- video file (saved in current computer)
- video URL (maybe youtube or other platform)
- audio file (saved in current computer)

Ideally, the current various question types should be able to manage this.


I saw that it should be possible to include videos in R markdown (untested):
https://stackoverflow.com/questions/43840742/how-to-embed-local-video-in-r-
markdown

but I'm unsure about whether this is the way to go.
Thanks.
Mayeul

Thanks to:
Vienna University of Economics and Business Powered By FusionForge