Skip to content

Instantly share code, notes, and snippets.

@houjun
Last active December 17, 2021 18:55
Show Gist options
  • Save houjun/59e9e6278909766fb8b5de9273cb2594 to your computer and use it in GitHub Desktop.
Save houjun/59e9e6278909766fb8b5de9273cb2594 to your computer and use it in GitHub Desktop.
""" flask_example.py
Required packages:
- flask
- folium
Usage:
Start the flask server by running:
$ python flask_example.py
And then head to http://127.0.0.1:5000/ in your browser to see the map displayed
"""
import folium
import base64
from flask import Flask
from folium import IFrame
app = Flask(__name__)
@app.route('/')
def index():
start_coords = (37.871666, -122.272781) # Berkeley
folium_map = folium.Map(location=start_coords, zoom_start=10)
encoded = base64.b64encode(open('/ATL_GulfCali_080309_600px.png', 'rb').read())
#html = '<img src="data:image/png;base64,{}">'.format
#iframe = IFrame(html(encoded.decode('UTF-8')), width=300, height=100)
html = f'''
<p>Velocity<p/>
<p style="color:red">Not real data<p/>
<p>Date: December 2021<p/>
<img src="data:image/png;base64,{encoded.decode('UTF-8')}">'''
iframe = IFrame(html, width=700, height=400)
popup = folium.Popup(iframe, max_width=1000)
marker = folium.Marker(location=[37.876663, -122.252742], popup=popup, tooltip='LBL 50B')
marker.add_to(folium_map)
return folium_map._repr_html_()
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment