jupyterlab-myst icon indicating copy to clipboard operation
jupyterlab-myst copied to clipboard

Jupyter widgets in MyST Markdown eval roles not rendered upon opening the notebook

Open nthiery opened this issue 9 months ago • 0 comments

Upon opening a notebook, an eval role (embedded in a Markdown cell) that produces ascii, Math or image output is rendered immediately. If instead the eval role produces a widget, then that widget is rendered as ascii instead.

Is there a reason for that behavior? Evaluating expressions without explicit user interaction upon opening a notebook is certainly borderline w.r.t. the trust model of notebooks, but I don't see a security difference between the above output types.

Steps to reproduce

  1. Create a new notebook with a markdow cell with the following content

    Inline ascii output:  
    {eval}`1+1`
    
    Inline latex output:  
    {eval}`__import__("IPython").display.Math(r"\sqrt{3}")`
    
    Inline image output:  
    {eval}`__import__("IPython").display.Image("https://nicolas.thiery.name/Enseignement/Info111/_images/tableau_de_bord.png")`
    
    Inline widget output:  
    {eval}`__import__("ipywidgets").IntSlider()`
    
  2. Close the notebook and reopen it

I get:

Image

I expected:

Image

Use cases in education

  • adaptative teaching: embedding widgets at the top and bottom of the student notebook providing feedback based on their progress in the course. Examples:
    • notebook top: is the student ready to work on that notebook? if not recommend remediation activities
    • notebook bottom: recommend follow up activities (flashcards, ...)
  • embedding a mini application in a notebook (like a dashboard) that starts immediately when the student opens the notebook

nthiery avatar Mar 29 '25 10:03 nthiery