ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Support loading widgets from a CDN in JupyterLab

Open saulshanabrook opened this issue 3 years ago • 2 comments

Problem

I am working on creating a custom widget and making it usable on all major notebook frontends.

Currently, if you publish an NPM package, than this supports VS Code, Colab, and Jupyter Book, because all of those frontends will look up the extension on a CDN (unpkg or jsdelivr) and download it remotely.

However, to get the extension to run in JupyterLab, you have to create a custom jupyterlab extension and distribute it via Python. This complicates the build process and makes it more cumbersome to have a write-once-run-anywhere widget.

Proposed Solution

If the jupyterlab widgets manager supported CDNs, then it would be a slightly less complicated experience to publish a custom widget package.

Other Details

See discussion with @jasongrout on Gitter

saulshanabrook avatar Aug 03 '22 22:08 saulshanabrook

A few relevant points:

  1. The bundles published on CDN are AMD modules, so the jlab manager would need to somehow be able to load AMD modules (e.g., include requirejs code)
  2. If the jlab manager grew this capability, I think it would be important to have it toggled with a setting. Not sure if that setting should default to on or off.
  3. The code to support something like this is in the HTML manager package: https://github.com/jupyter-widgets/ipywidgets/blob/master/packages/html-manager/src/libembed-amd.ts
  4. Voila also supports widgets via loading them from CDN, but I think they are actually moving to using the jlab widget packages.

jasongrout avatar Aug 03 '22 23:08 jasongrout

As an aside: There might be a benefit to solving this on the JupyterLab level. Having JupyterLab be able to load/install extensions from CDN/NPM would also bring benefits to lab.

vidartf avatar Aug 12 '22 11:08 vidartf