[VSCode] Unable to find widget '@finos/perspective-jupyterlab'
Bug Report
PerspectiveWidget doesn't work in VSCode because the Jupyter extension cannot find widget frontend scripts in @finos/perspective-jupyterlab.
Steps to Reproduce:
- Install Jupyter and Python VSCode extensions.
- Open a notebook, select a kernel that has
perspective-pythoninstalled. - Try to display a
PerspectiveWidgetinstance.import polars as pl from perspective.widget import PerspectiveWidget display(PerspectiveWidget(pl.DataFrame({"x": range(5), "y": range(5)})))
Expected Result:
The widget shows and works.
Actual Result:
-
In the cell's output, instead of the widget, a JS error is displayed, saying that the widget class could not be found. I'm paraphrasing because the error message shown was truncated and I didn't bother digging it up from logs as the cause seems clear (explained below).
-
VSCode displays this popup:
Unable to find widget '@finos/perspective-jupyterlab' version '~3.6.1' from configured widget sources ["jsdelivr.com","unpkg.com"]. Expected behavior may be affected. Click here for more information.
-
In the Output view (View > Output), Jupyter logs contain:
12:39:49.139 [error] Widget Error: Failed to access CDN https://unpkg.com/ after 0 attempt(s), TypeError: Failed to fetch 12:39:55.220 [error] Widget Script @finos/perspective-jupyterlab#~3.6.1 was not found on on any cdn 12:39:55.220 [warn] Widget Script Source not found for @finos/perspective-jupyterlab@~3.6.1 from cdn 12:39:55.221 [warn] Widget Script Source not found for @finos/perspective-jupyterlab@~3.6.1 from local 12:39:55.221 [error] Script source for Widget @finos/perspective-jupyterlab@~3.6.1 not found in cdn, local 12:39:55.240 [error] Widget load failure {} [ 'jsdelivr.com', 'unpkg.com' ] { classNa<username>: 'PerspectiveModel', moduleNa<username>: '@finos/perspective-jupyterlab', moduleVersion: '~3.6.1', isOnline: true, ti<username>dout: false, error: '{}' }
Environment:
- Arch Linux
- VSCodium (1.102.14746)
- CPython 3.12.8
Additional Context:
-
I also tried installing
perspective-pythonglobally, it didn't help. -
From what was said in https://github.com/microsoft/vscode-jupyter/issues/12763#issuecomment-1445489782, I believe that this issue is caused by how
@finos/perspective-jupyterlabis packaged and distributed. Looking at https://www.jsdelivr.com/package/npm/@finos/perspective-jupyterlab?tab=files, thedist/folder is indeed missing. -
Other widget labextensions work fine. To list a few: anywidget, jupyter-vuetify. They all package their files under
dist/. -
Based on how widget loading issues are being handed by vscode-jupyter maintainers, it seems they believe that these issues are to blame on the widget packages rather than their extension. I don't know enough about extension development for either VSCode or JupyterLab to comment on that.
From my experience, it has basically never worked in Notebooks in VSCode -- not just that something broke it recently.
It’s also not usable in Notebooks on Databricks.
Please find attached examples with error messages below.
VSCODE
Editor:
Notification:
Error message: Unable to find widget '@finos/perspective-jupyterlab' version '~3.7.4' from configured widget sources ["jsdelivr.com","unpkg.com"]. Expected behavior may be affected. Click [here](https://aka.ms/PVSCIPyWidgets) for more information.
DATABRICKS
Error message: Could not load module @finos/perspective-jupyterlab from https://cdn.jsdelivr.net/npm/@finos/perspective-jupyterlab@~3.7.4/dist/index.js. The widget author may have not published the widget JavaScript or there may have been a network error.
TEST CODE
Cell 1:
from datetime import date, datetime
import numpy as np
import pandas as pd
import perspective
data = pd.DataFrame({
"int": np.arange(100),
"float": [i * 1.5 for i in range(100)],
"bool": [True for i in range(100)],
"date": [date.today() for i in range(100)],
"datetime": [datetime.now() for i in range(100)],
"string": [str(i) for i in range(100)]
})
table = perspective.table(data, index="float")
display(table)
Cell 2:
w = PerspectiveWidget(
data,
plugin="X Bar",
aggregates={"datetime": "any"},
sort=[["date", "desc"]]
)
display(w)