displayjupyterhubipycanvas

How to display Canvas with ipycanvas on Jupyterhub?


The following code works fine on my local machine/environment:

from ipycanvas import Canvas
canvas = Canvas(width=300, height=300)
display(canvas)

But using jupyterhub installed on VM on GCP it does no longer display the canvas.

What is missing ?


Solution

  • ipycanvas is a package which needs to be installed in the same environment as the jupyterlab instance. Additionally, you need to have nodejs installed, and you need to enable the jupyterlab ipycanvas widget.

    These are all covered in the ipycanvas installation instructions:

    Using conda

    conda install -c conda-forge ipycanvas
    

    JupyterLab extension

    If you have JupyterLab, you will also need to install the JupyterLab extension. In order to install the JupyterLab extension, you will need npm to be installed. You can easily install npm with conda:

    conda install -c conda-forge nodejs
    

    Then you can install the JupyterLab extension:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager ipycanvas
    

    Since you mention that you're on jupyterhub, if you're on a cluster and you're not the administrator, it's possible you don't have the permissions to do this. If that's the case, reach out to your cluster administrator - it's possible they don't allow users to enable extensions.