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.

Empty plot when enabling json data_transformer

See original GitHub issue

Below is my code, I get an empty plot. I am using JupyterLab

import altair as alt
import pandas as pd
alt.data_transformers.enable("json")

size = 10
df = pd.DataFrame(
    {"key": np.random.choice(list("ABC"), size), "val": np.random.rand(size)}
)
alt.Chart(df).mark_point().encode(y="key:N")

My versions are: altair: 3.2.0 jupyterlab: 1.0.4

I tried looking through the page response when inspecting the network activity on Chrome, I am seeing a forbidden error.

<div class="error">
    <h1>403 : Forbidden</h1>
    <p>The error was:</p>
    <div class="traceback-wrapper">
    <pre class="traceback"> is not a file</pre>
    </div>
</div>

Below is the to_dict() from the altair object.

{'config': {'view': {'width': 400, 'height': 300}, 'mark': {'tooltip': None}},
 'data': {'url': 'altair-data-e47f5911f8d2367541736476ae610606.json',
  'format': {'type': 'json'}},
 'mark': 'point',
 'encoding': {'y': {'type': 'nominal', 'field': 'key'}},
 '$schema': 'https://vega.github.io/schema/vega-lite/v3.4.0.json'}

and the datafile exists in the local path

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jakevdpcommented, Oct 15, 2019

This looks like the same issue as reported in https://github.com/jupyterlab/jupyterlab/issues/7017, which has been fixed as of JupyterLab version 1.1.0. Based on this, I believe that updating Jupyterlab will fix your issue.

1reaction
rschwarzcommented, Feb 22, 2022

I also have the same behavior as the above two posts, using versions:

altair               4.2.0
jupyter-client       7.1.2
jupyter-core         4.9.2
jupyter-server       1.13.5
jupyterlab           3.2.9
jupyterlab-server    2.10.3

While passing a pandas DataFrame works, using any of the two transformers does not. Neither does manually saving to CSV and refering to that filename.

UPDATE: To expand on the experiment with manual CSV saving, here are a couple of URLs I tried, some of which worked. In this case, I did not enable any data_transformer and saved the file to foobar.csv next to the notebook files, which is also from where I started JupyterLab.

FAIL: "foobar.csv"     # but works with classic Jupyter Notebook      
FAIL: "files/foobar.csv"
OK:   "/files/foobar.csv"
OK:   "http://localhost:8888/files/foobar.csv"
FAIL: "http://localhost:8888/files/foobar.csv?_xsrf=2%7Ce1d7e552%7Cd48f09f31845ffbba0881670bae6d705%7C1645528121"
FAIL: "http://localhost:8888/lab/tree/34.fcoagg.csv"

Here, the latter two are the URLs which I get whith right-click on the CSV file and then either “Copy download link” or “Copy shareable link”.

To conclude, the URL that works is the “download link” with the query parameter removed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty downloaded chart when alt.data_transformers.enable ...
The JSON data transformer causes the chart to not be self-contained, and this is by design. The output will work as long as...
Read more >
Altair plot is empty when alt.data_transformers.enable('json ...
It appears that the notebook then fails to read data from the json file and empty plot is displayed in the output cell....
Read more >
Using JSON data transformer for large dataset - Google Groups
I am plotting a large dataset, so I am trying to use the JSON data transformer: alt.data_transformers.enable('json').
Read more >
Data is getting embedded via a local json file - altair
alt.data_transformers.enable('json'). If you want to restore the default data transformer which embeds data directly into the chart, run
Read more >
Configuring the JSON data transforms settings column on the ...
Pega Platform displays the Settings tab on the data transform rule form for the JSON data model format. Use the Settings tab to...
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