Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render map and widgets in HTML web page #592

Open
lorenae opened this issue May 13, 2020 · 6 comments
Open

Render map and widgets in HTML web page #592

lorenae opened this issue May 13, 2020 · 6 comments
Labels

Comments

@lorenae
Copy link

lorenae commented May 13, 2020

Hi!
I'm new to ipyleaflet and it's really a great tool!!

I have a map similar to the WealthOfNations map. I'd like to export the map and the controls and embed in an HTML page.

Following the suggestions from this issue I've saved the map, but this not includes the controls.

I've also obtained HTML using the "Embed widgets" option in the notebook. This produces the map and the widgets, but not the behavior (it doesn't refresh the graphics according to on_hover).

Any suggestions?
thanks in advance!
Lorena

@giswqs
Copy link
Contributor

giswqs commented May 13, 2020

As far as I know, customized ipywidgets are not supported in the exported HTML. It would be nice if it can be supported in the future. The geemap package built upon ipyleaflet can also export HTML with a GUI. Again, customized ipywidgets are not supported as this moment.

@martinRenou
Copy link
Member

Following the suggestions from this issue I've saved the map, but this not includes the controls.

This is a bug, it should work.

@martinRenou
Copy link
Member

I've also obtained HTML using the "Embed widgets" option in the notebook. This produces the map and the widgets, but not the behavior (it doesn't refresh the graphics according to on_hover).

This will never be fixed though. The custom on_hover logic relies on Python callbacks that are executed in the kernel, server side. Using a static HTML page, the Python kernel is not there anymore and cannot execute this logic. I would recommend looking at Voila though, which allows you to serve a page with widgets in it, and the Python kernel is still alive server side.See this demo for an example of ipyleaflet with Voila.

@deeplook
Copy link
Contributor

I'm trying to save a map with a GeoJSON layer on it as HTML. I can see the GeoJSON inside the saved HTML, but when I open the HTML in a browser I see only the basemap but no GeoJSON. Should this work? I've tried other MIME type for the GeoJSON inside the HTML, but in vain. See code below.

import requests
from ipyleaflet import Map, GeoJSON

url = "https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json"
m = Map(zoom=1)
m += GeoJSON(data=requests.get(url).json())
m.save('my_map.html', title='My Map')

@martinRenou
Copy link
Member

@deeplook yes this should work. This looks like a bug. It might be related to the issue with the controls.

@scottyhq
Copy link
Contributor

Just came across this while trying to save the map example with linked ipywidgets https://ipyleaflet.readthedocs.io/en/latest/api_reference/widget_control.html

m.save() only shows the basemap. A partial workaround is going through embed_minimal_html but then the slider widget ends up below the map instead of it's upper right position. This is an example where linked widgets could be nice to save without needing python running via Voila:

from ipyleaflet import Map, basemaps, WidgetControl
from ipywidgets import IntSlider, jslink

m = Map(center=(46.01, 6.16), zoom=12, basemap=basemaps.Stamen.Terrain)
zoom_slider = IntSlider(description='Zoom level:', min=0, max=15, value=7)
jslink((zoom_slider, 'value'), (m, 'zoom'))
widget_control1 = WidgetControl(widget=zoom_slider, position='topright')
m.add_control(widget_control1)

# Two approaches to saving
# 1) no visible slider
#m.save('ipyleaflet_widgets.html', title='Widgets export')

# 2) functioning linked slider, but under map instead of in topright
from ipywidgets.embed import embed_minimal_html
embed_minimal_html('ipyleaflet_widgets1.html', views=[m,zoom_slider], title='Widgets export')

cc @davidbrochart in case you're aware of other workarounds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants