Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support interactive code exercises #17

Closed
joelostblom opened this issue Aug 4, 2024 · 6 comments
Closed

Support interactive code exercises #17

joelostblom opened this issue Aug 4, 2024 · 6 comments
Labels
P2 Important to address in the near future

Comments

@joelostblom
Copy link
Owner

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 coatless-quarto/pyodide#7. Relevant resource for book setup in pyodide https://github.com/coatless-quarto/pyodide/blob/main/examples/book/_quarto.yml

@joelostblom joelostblom added the P2 Important to address in the near future label Aug 4, 2024
@joelostblom
Copy link
Owner Author

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 r-wasm/quarto-live#44

@joelostblom
Copy link
Owner Author

r-wasm/quarto-live#44 has been implemented so we're good to go with using this extension for all our interactive exercises!

@rorywhite200
Copy link
Collaborator

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.

  • It looks like we can't pass variables from python cells to pyodide so we need to convert all that are interdependent
  • In pyodide cells you cannot use local data, so must import with url path
  • the package rpy2 is not compatible with pyodide as it's not written in plain python

@joelostblom
Copy link
Owner Author

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 jupyterlite/jupyterlite#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 pyodide/pyodide#4585 and posit-dev/py-shinylive#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
Copy link
Collaborator

rorywhite200 commented Aug 29, 2024

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
Copy link
Owner Author

Closing as we are using interactive exercises since #32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Important to address in the near future
Projects
None yet
Development

No branches or pull requests

2 participants