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.

Data source in Jupyter needs full URL

See original GitHub issue

In Jupyter Lab I have seattle-weather.csv, bar.vl.json and a notebook all in the same folder. The data is from the example data sets, as is the Vega Lite:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "seattle-weather.csv"},
  "mark": "bar",
  "encoding": {
    "x": {"timeUnit": "month", "field": "date", "type": "ordinal"},
    "y": {"aggregate": "count", "type": "quantitative"},
    "color": {"field": "weather", "type": "nominal"}
  }
}

Opening the Vega Lite file directly creates a tab with the bar chart rendered as expected. In the notebook I need to pass the full URL to Altair to create the same visualisation:

alt.Chart('http://localhost:8888/files/seattle-weather.csv').mark_bar().encode(
    x='month(date):O',
    y='count():Q',
    color='weather:N'
)

Why does alt.Chart('seattle-weather.csv')..... not work in the notebook? Can the docs be updated to include guidance around this use case scenario?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
joelostblomcommented, Jul 9, 2021

I just discovered that it works as expected with /files instead of just files.

1reaction
jakevdpcommented, Mar 26, 2021

I don’t think the full URL is actually required. For example, I ran this in a local JupyterLab instance and it produced a correctly rendered chart:

import altair as alt
from vega_datasets import data
!curl -O {data.seattle_weather.url}

alt.Chart('files/seattle-weather.csv').mark_bar().encode(
    x='month(date):O',
    y='count():Q',
    color='weather:N'
)

(This will only work if you have not used the %cd magic command to change the working directory from the JupyterLab root. I believe there are also caveats about different ways to start kernels and different jupyter configuration settings that will make this fail, because the location in which the curl command is run can diverge from the JupyterLab root directory)

Read more comments on GitHub >

github_iconTop Results From Across the Web

JupyterLab URLs — JupyterLab 3.6.0a5 documentation
A workspace file in a JSON file with a specific spec. There are two top level keys requires, data , and metadata ....
Read more >
can't access data from URL in pandas/jupyter notebook
1 Answer 1 · The data source you are using has discontinued publishing the 'recovery' statistic. You can read the details here. It...
Read more >
Access ODBC Data Sources in Jupyter Python Notebook ...
Querying Data from Python Notebook​​ Start Jupyter by running the command jupyter notebook. You should see browser open up and load the homepage...
Read more >
How to Upload Source Data to Jupyter Notebook in Python
Example data used in this lecture: FBOne.csvhttps://drive.google.com/file/d/1luLaEPCWIPiy74ohsV-Xpkx79vtSnRUG/view?usp=sharingFacebook stock ...
Read more >
Loading and accessing data in a notebook
To access data from a local file, you can load the file from within a notebook, or first load the file into your...
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