joelostblom / viz-oer

An interactive open educational resource for learning data visualization
https://joelostblom.github.io/viz-oer/
0 stars 0 forks source link

Support interactive code exercises #17

Closed joelostblom closed 1 month ago

joelostblom commented 3 months ago

It would be highly beneficial if students could code directly in the online book instead of copy pasting to their local environment. I believe that would allow them to be more immersed in the content and have a lower activation barrier than copy pasting and making sure they have all packages locally etc.

Hopefully we can do this via https://github.com/coatless-quarto/pyodide and https://github.com/coatless/quarto-webr, but currently blocked by https://github.com/coatless-quarto/pyodide/issues/7. Relevant resource for book setup in pyodide https://github.com/coatless-quarto/pyodide/blob/main/examples/book/_quarto.yml

joelostblom commented 2 months ago

There is now an official extension in https://github.com/r-wasm/quarto-live that we can use. Just need support for altair charts there https://github.com/r-wasm/quarto-live/issues/44

joelostblom commented 2 months ago

https://github.com/r-wasm/quarto-live/issues/44 has been implemented so we're good to go with using this extension for all our interactive exercises!

rorywhite200 commented 2 months ago

That's great news! It is working for me in our textbook. Looks like we need to make a few changes since we are using pyodide cells.

joelostblom commented 2 months ago

It looks like we can't pass variables from python cells to pyodide so we need to convert all that are interdependent

That makes sense I believe. I think we can just have a hidden pyodide cell initiating anything we have already defined in a regular python cell (unless it is instructive to repeat it more explicitly).

In pyodide cells you cannot use local data, so must import with url path

Hmm, where did you see this? I believe it should work to read local files, see e.g. https://pyodide.org/en/stable/usage/file-system.html and https://github.com/jupyterlite/jupyterlite/issues/119 (although specifically for jupyterlite). Having that said, I thnk it is completely fine that we run everything from

Might also be helpful for us later https://github.com/pyodide/pyodide/issues/4585 and https://github.com/posit-dev/py-shinylive/issues/8

the package rpy2 is not compatible with pyodide as it's not written in plain python

We shouldn't need this anywhere in pyodide I think. Were you thinking of anything specific where it might be needed?

rorywhite200 commented 2 months ago

Hmm, where did you see this? I believe it should work to read local files, see e.g. https://pyodide.org/en/stable/usage/file-system.html and jupyterlite/jupyterlite#119

Great, I'll give those a try.

We shouldn't need this anywhere in pyodide I think. Were you thinking of anything specific where it might be needed?

Currently it is used in the show_df function. This isn't a requirement for our interactive exercises but its more that we will need to change our imports so that we import each package twice - once in python for showing the df / preset visualizations and again in pyodide for coding exercises.

joelostblom commented 1 month ago

Closing as we are using interactive exercises since #32