question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

altair.data_transformers.enable('json') leads to invalid data URLs in JupyterLab when switching from Altair 3.3.0 to 4.0.0

See original GitHub issue

To reproduce, use the latest version (as of this writing) of altair and jupyterlab:

altair==4.0.0
ipykernel==5.1.3
ipython==7.10.1
jupyter==1.0.0
jupyter-client==5.3.4
jupyter-console==6.0.0
jupyter-core==4.6.1
jupyterlab==1.2.4
jupyterlab-server==1.0.6
vega-datasets==0.7.0

In Jupyter lab open a new notebook and try:

from vega_datasets import data
import altair as alt

alt.data_transformers.enable('json')
alt.renderers.enable('default')

source = data.cars()

alt.Chart(source).mark_circle(size=60).encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
    tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon']
).interactive()

This leads to an empty chart with the following error in the JavaScript console:

vega@5?noext:1 GET http://localhost:8888/altair-data-4d45d69bbd706eda330e96e79ad4bf46.json 404 (Not Found)
vega@5?noext:1 WARN Infinite extent for field "Horsepower": [Infinity, -Infinity]
vega@5?noext:1 WARN Infinite extent for field "Miles_per_Gallon": [Infinity, -Infinity]

And in the Jupyter logs the error reads:

[W 16:56:10.144 LabApp] 404 GET /altair-data-4d45d69bbd706eda330e96e79ad4bf46.json (::1) 1.60ms referer=http://localhost:8888/lab

If I revert to altair==3.3.0 this error disappears and the data gets correctly loaded from disk and rendered. In that case the data URL (read from from the browser dev tools) becomes http://localhost:8888/files/altair-data-4d45d69bbd706eda330e96e79ad4bf46.json?_xsrf=<blah> (where I replaced the long string at the end with <blah).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
jakevdpcommented, Dec 15, 2019

With #1872, in the next version of Altair (4.1 or newer) you’ll be able to run

alt.data_transformers.enable('json', urlpath='files')

to make the transformer work correctly in JupyterLab with the default renderer. Without a way for the backend to detect what frontend you’re using (an idea the Jupyter team has long resisted) I don’t think there’s any way to make this more automatic.

3reactions
jakevdpcommented, Jan 10, 2020

The issue is that localhost filepaths are unpredictable between different flavors of Jupyter notebook.

I’d suggest avoiding the JSON/CSV transformer in favor of the data_server transformer, which should work regardless of what Jupyter frontend you’re on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data transformers — Altair 4.2.0 documentation
Pandas Dataframe has to be sanitized and serialized to JSON. ... A data transformer is a Python function that takes a Vega-Lite data...
Read more >
Data is getting embedded via a local json file - altair
If you want to restore the default data transformer which embeds data directly into the chart, run alt.data_transformers.enable('default').
Read more >
debugging schema validation issues - how to?
So, I dumped my chart to json: json = chart.to_json(validate=False) ... Altair git, https://github.com/altair-viz/altair/issues.
Read more >
Altair Data Server.ipynb - Colaboratory
Altair charts are built on vega-lite, a visualization grammar that encodes charts in JSON before rendering them in your browser with Javascript. For...
Read more >
Declarative statistical visualization library for Python
Auto-generate Altair Python code from a Vega-Lite JSON spec. ... To use Altair for visualization, you need to install two sets of tools....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found