sagemathinc / cocalc

CoCalc: Collaborative Calculation in the Cloud
https://CoCalc.com
Other
1.17k stars 216 forks source link

support the ipycanvas widget in cocalc-jupyter #5159

Closed williamstein closed 2 months ago

williamstein commented 3 years ago

See https://ipycanvas.readthedocs.io/en/latest/

williamstein commented 3 years ago

Probably this involves:

  1. Installing all the relevant code for the upstream project, and
  2. Porting the frontend code to cocalc-jupyter, since it probably (?) uses the generic widget extensions feature, which we don't support.
sheinb commented 3 years ago

I'd add that this would provide a very convenient way to incorporate turtle graphics in a notebook for teaching, along with efficient graphics for games and visualizations like 'game of life'.

williamstein commented 3 months ago

This is a custom widget, and our goal with jupyter now is that ALL custom widgets be fully supported. I just tried this and something mysterious does go wrong:

image

This also does not work for my in JupyterLab 3.6:

image

Ipycanvas is also broken for me in a fresh install with JupyterLab 4.2.3:

image

It does work in colab, though you have to do something special to enable it (for security reasons):

image

but I think colabs widgets setup is several years old (?), so it's maybe more likely to support something that used to work:

image

In any case, it's very likely a bug that this doesn't work, and we should support it.

Upstream issues saying this is broken on mybinder:

williamstein commented 3 months ago
!pip install ipycanvas
from ipycanvas import Canvas

canvas = Canvas(width=200, height=200)

canvas.fill_rect(25, 25, 100, 100)
canvas.clear_rect(45, 45, 60, 60)
canvas.stroke_rect(50, 50, 50, 50)

canvas
williamstein commented 3 months ago

This DOES work in JupyterLab 4.2.4. Definitely a bug to be fixed:

image
williamstein commented 2 months ago

The basics work, but something else goes wrong with this example from the docs:

from ipycanvas import Canvas

canvas = Canvas(width=100, height=50)

def perform_drawings():
    canvas.font = "32px serif"
    canvas.fill_text("Voilà!", 10, 32)

canvas

then in another cell

perform_drawings()

It works the first time. If you then refresh the browser, it crashes and further evaluation does not work.

This is also broken in the same way when used with JupyterLab.

This is an upstream bug that has been opened 1.5 years with no comment: https://github.com/jupyter-widgets-contrib/ipycanvas/issues/322

So basically now cocalc matches the jupyterlab behavior, which is the best we can hope for.

williamstein commented 2 months ago

I'm going to close this; it's not our bug and I don't know what to do about it.