Why It Works Outside AVD
When working outside your AVD setup (such as on a local machine or a cloud environment with internet access), the widget JavaScript loads successfully from the CDN, enabling chart display.
Solutions for Secure, Offline Environments
1. Use Plotting Libraries That Do Not Rely on CDN for Rendering
Libraries like Matplotlib, Seaborn, and Plotly (using static image rendering) generate charts server-side and can display images directly in Jupyter notebooks, even offline. Altair and libraries using Jupyter widgets frequently require frontend code loading, sometimes from CDNs.
2. Configure anywidget/Altair for Local Serving of JS
Anywidget permits bundling custom widget JS locally. This involves either:
-
Building the widget entirely client-side and serving assets from the local filesystem.
-
Using tools like jupyterlab-manager and nbextension install to install widgets locally so that frontend JavaScript is available offline.
This may require custom setup:
-
Rebuilding the widget JS and configuring Jupyter to serve the static assets from disk.
-
Ensuring that the nbextension for anywidget is installed and enabled.
3. Download and Serve Required JS Locally
As an advanced workaround, obtain the required JavaScript files offline (for example, download from the CDN on a machine with internet access), copy them into your secure environment, and modify the relevant widget code or notebook config to load the JS from local file paths instead. This may require patching anywidget or Altair and updating notebook/lab settings.
4. Change Plotting Approach in Jupyter
-
Instead of alt.JupyterChart, use chart.save('plot.html') or chart.save('plot.png') and then display the saved image using IPython display utilities.
-
This avoids widget rendering and uses static output compatible with offline environments.
Example: Matplotlib Alternative
import matplotlib.pyplot as plt
plt.bar(source['a'], source['b'])
plt.xlabel('a')
plt.ylabel('b')
plt.show()
This renders a static PNG inline in the notebook, requiring no external assets to load.
Next Steps
-
For Altair, consider using chart.show() or saving charts as images, since those do not require widget JavaScript.
-
For advanced widget frameworks (anywidget, ipywidgets), consult documentation on offline installations and local JS serving.
-
Check if the JupyterLab/Notebook extensions for anywidget are fully installed (not just pip) within your AVD environment.
If interactive widget charts must be used offline, further setup with local nbextensions/JupyterLab extensions is needed, or a switch to purely static plotting libraries is recommended for guaranteed display.