Search code examples
pythonfolium

Folium: How to show a map from a saved html file in ipynb


I have a folium map saved locally as a html file, now I want to read that map.html file to show a map in another ipynb cell/notebook.

Minimum code to generate the local file:

import folium

m = folium.Map(location=[45.5236, -122.6750]) 
m # to view the map if needed
m.save('map.html')

Esentially I'm trying to find any way to save a map locally (doesn't need to be html) and read it later in some other ipynb notebook.

I am able to find ways of sharing it on the web but my use case is limited to ipynb.


Solution

  • Have you tried loading it as an IFrame in the second ipynb ?

    import folium
    
    # op map
    m = folium.Map([45.5236, -122.6750])
    
    # adding a blue marker/icon
    folium.Marker(location=[45.5236, -122.6750], icon=folium.Icon(color="blue")).add_to(m)
    
    m.save("map.html") # saving it locally
    

    from IPython.display import IFrame
    
    IFrame(src="map.html", width=800, height=350)
    

    Output (in Jupyterlab) :

    enter image description here