cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Altair charts don't work in offline mode

DavidFrench
New Contributor

Hello,

We are running a secure Databricks environment (no internet access) within an Azure Virtual Desktop and are currently unable to get any charts to display. They work if we access the environment from outwith the AVD, but not when we access it from within the AVD.

Some example code (from the altair documentation😞

import altair as alt
import pandas as pd

source = pd.DataFrame({
    'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
    'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
})

chart = alt.Chart(source).mark_bar().encode(
    x='a',
    y='b'
)

jchart = alt.JupyterChart(chart)
jchart

This leads to the error message "Could not load module anywidget from https://cdn.jsdelivr.net/npm/anywidget@~0.9.*/dist/index.js. The widget author may have not published the widget JavaScript or there may have been a network error.", although the anywidget package is already installed.

Can anyone suggest anything we could try?

1 REPLY 1

mark_ott
Databricks Employee
Databricks Employee

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

python
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.

Join Us as a Local Community Builder!

Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!

Sign Up Now