Comments (17)
@scwilkinson @Juanlu001 thanks for the bug report. The method we're using in the example is to export data for visualization to a local file points.geojson
, and then load the file from the local web server which Jupyter runs from the Python kernel (localhost:8888
normally). It looks like Jupyter Lab uses a different URL path to server local files than the root web server.
As a workaround, could you try exporting the dataframe to a python dict variable, and then creating the mapboxgl.viz.CircleViz from the python variable? The approach below should be the code you need:
# Create a geojson file export from a Pandas dataframe
data = df_to_geojson(df, properties=['Avg Medicare Payments', 'Avg Covered Charges', 'date'],
lat='lat', lon='lon', precision=3)
# Generate data breaks and color stops from colorBrewer
color_breaks = [0,10,100,1000,10000]
color_stops = create_color_stops(color_breaks, colors='YlGnBu')
# Create the viz from the dataframe
viz = CircleViz(data,
height='400px',
access_token='pk',
color_property = "Avg Medicare Payments",
color_stops = color_stops,
center = (-95, 40),
zoom = 3,
#below_layer = 'waterway-label',
style_url='https://openmaptiles.github.io/osm-bright-gl-style/style-cdn.json',
)
viz.show()
from mapboxgl-jupyter.
agreed that in-memory object usage is better than storing temporary files.
from mapboxgl-jupyter.
Your rendermime extension that creates the visualization has access to this resolver, so it should be able to take a filename and convert it to a url it can use. It's passed in the arguments: https://github.com/jupyterlab/jupyterlab/blob/d740dee4980557a1d58fe0371bc467166f6cd9ac/packages/rendermime-interfaces/src/index.ts#L284
You probably want to use the getDownloadUrl
function of that object: https://github.com/jupyterlab/jupyterlab/blob/d740dee4980557a1d58fe0371bc467166f6cd9ac/packages/rendermime-interfaces/src/index.ts#L332
from mapboxgl-jupyter.
It works, and I actually prefer this to the file-based approach :) Thanks!
from mapboxgl-jupyter.
@ryanbaumann For example, I have a Dockerfile
in my root directory when I open JupyterLab. If I go to http://localhost:8888/files/Dockerfile
it will be downloaded.
If I change the example in the README to add /files/
to the filename, I think it appears to work for me in JupyterLab:
from mapboxgl-jupyter.
Be careful that using the absolute url /files/filename.ext
may not work if you have a url prefix (for example, I think in JupyterHub there is a prefix of the username?). It also is a bit tricky if you have
a file not in the root directory of the server.
If you use a relative URL, the frontend has a URL resolver that takes the url and should be able to give you back a URL to get that file.
from mapboxgl-jupyter.
I've had this same issue with mapboxgl 0.5.1, pip 9.0.1, python 3.6.4, and JupyterLab 0.31.8.
A vanilla Jupyter Notebook launched in the same environment shows the data just fine!
I'm on macOS and use Firefox (58.0.2), but I have the same problem in Chrome (64.0.3282.167).
from mapboxgl-jupyter.
I should also note that I've had very similar problems with other libraries similar to mapboxgl (gmaps, folium etc) in JupyterLab, so potentially it's the problem?
from mapboxgl-jupyter.
This works for me! I wasn't paying attention to the terminal output from JupyterLab, which includes:
[W 10:23:11.345 LabApp] 404 GET /points.geojson (::1) 2.29ms referer=http://localhost:8888/lab
Thank you!
from mapboxgl-jupyter.
Awesome @scwilkinson @Juanlu001, glad the local data variable works!
I'll leave this ticket open. We want to figure out an architecture for Jupyter Lab where the visualization can asynchronously load the data for performance and exporting the viz to an HTML file export reasons - this is especially useful when the data is very large.
from mapboxgl-jupyter.
In Jupyterlab you can use the /files/<filename>
path to get a raw file. I know altair is going through a lot of the same design decisions, with their new version. They now support conditionally writing a temporary json file, which you can enable if you have a lot of data that you don't want to inline into the notebook.
Do you need anything from Jupyterlab to make progress on this?
from mapboxgl-jupyter.
@saulshanabrook can you show a quick example of how to directly link to a file in Jupyter Lab (and return the raw file, like a download link)?
from mapboxgl-jupyter.
excellent, thanks @saulshanabrook. That's perfect, we can add to the docs for how to run in Jupyter Lab. Closing!
from mapboxgl-jupyter.
Great!
from mapboxgl-jupyter.
I just realized that the way you are displaying data is to send an html iframe to the browser, so you won't have access to this url resolver.
Another way to do it that more clearly separates the backend from the rendering in the frontend is to define a mimetype for your data (rather than encoding everything into html in the kernel). Send your data over to the frontend in some semantically meaningful format. Then write a JupyterLab extension that takes this data and renders it onto the page, and uses the url resolver to resolve links.
from mapboxgl-jupyter.
Agree we could make a Jupyter Lab extension in the future - let's open up a new ticket to propose that sort of a solution, since it wouldn't be compatible with other HTML Notebook ecosystems.
from mapboxgl-jupyter.
wouldn't be compatible with other HTML Notebook ecosystems.
Since you can transmit a mimebundle with both HTML and this new format included, it could be backwards compatible, with the disadvantage of transmitting data twice in two different formats.
from mapboxgl-jupyter.
Related Issues (20)
- Mapbox Jupyter doesn't render ChoroplethViz HOT 7
- New feature to edit colour legends title
- TemplateNotFound in conda environment HOT 7
- Coverage/Coveralls hangs indefinitely HOT 1
- Examples don't work as shown, due to Jupyter "Blocking request with no referer" HOT 5
- Support MapboxGL 'step' expression for color and height function types HOT 5
- Is there a way to hide the "token = os.getenv('MAPBOX_ACCESS_TOKEN')" HOT 5
- Will Mapbox add support for JupyterLab? HOT 6
- Please add interactive callback events to this widget.
- Adding search for map HOT 1
- Heat Map in time HOT 3
- Subplot support HOT 4
- How to hide the legends for GraduatedCircleViz? HOT 1
- Example displays base map but not points HOT 2
- any chance multiple viz can be combined in a single view? HOT 1
- viz.create_html() rounds lat/lng to 4 decimal places which drops accuracy to 11m
- How to hide null/Nan values on a CircleViz ? HOT 3
- Uncaught Error: An API access token is required to use Mapbox GL.
- Mapboxgl cannot be imported on Windows 10 after conda install
- mapbox doesn't render points on jupyter notebook running on Databricks. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapboxgl-jupyter.