coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
381 stars 18 forks source link

Code exercises #121

Open coatless opened 8 months ago

coatless commented 8 months ago

Offer the code exercise feature from {learnr}.

This should match more closely with the desire of https://github.com/coatless/quarto-webr/issues/25

Sample exercise: https://github.com/rstudio/learnr/blob/aeb8144f5335a1132dbb1c0a0302fd2f3e94b875/inst/tutorials/ex-data-filter/ex-data-filter.Rmd#L236

Proposed markup:

```{webr-r}
#| label: ex01
#| exercise: true
#| label: ex01-solution
filter(flights, dep_time <= 600 | dep_time == 2400)
#| label: ex01-hint-1
# any number with a zero exponent is equal to one
NA ^ 0
#| label: ex01-hint-2
# unknown value or true evaluates to true
# (because if one operand of "or" is true, we can be sure the result is true)
NA | TRUE
#| label: ex01-hint-3

# false and unknown value evaluates to false
# (because if one operand of "and" is true, we can be sure the result is false)
FALSE & NA
#| label: ex01-hint-4
# this is not a logical comparison, it's a numerical calculation involving an
# unknown value, thus resulting in an unknown value
NA * 0
joelostblom commented 6 months ago

Would this feature also support rendered radio buttons for e.g. MCQs as well (as in https://nareal.github.io/naquiz/example.html)? It's easy to emulate this with code otherwise, but I'm curious since I believe learnr and webexercises also supports some of these rendered simpler html elements.

Also of interest, do you think the approach here would lend it self well to be supported in the pyodide implementation as well? I'm planning to write a textbook using R and Py and I'm excited to see the developments here =)

coatless commented 6 months ago

@joelostblom the focus would solely be on the code evaluation portion.

The MC/MS/FIB offerings from {learnr} are better left as a standalone quarto extension as the format is reusable across languages like quarto-quiz or the naquiz format you identified. Plus, for language-specific implementations like {webexercises}, these would address content specific to R. For example:

Given a seed of <dynamic-seed> what would be the mean of the vector given by <dynamic-numbers>.

  • Option 1
  • Option 2
  • ...

At some point, I could imagine the joining of quarto-webr/quarto-pyodide + quarto-quiz to form quarto-learn, but I'm not likely to lead that project.

davidkane9 commented 5 months ago

This would be excellent! My use case is writing a Quarto book with learnr exercises embedded in it. Right now, I need to keep my book separate from my tutorials. It would be much nicer to put everything into a single document. In this way, students could (be forced to) answer questions as they move through the textbook.