1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objects as go
from urllib.request import urlopen
import json
from django_plotly_dash import DjangoDash
from django import template
register = template.Library()
@register.filter(name='main')
def loaddash():
#df = pd.read_csv("fips-unemp-16.csv", dtype={"fips": str})
#df = pd.read_csv("admin2.csv", dtype={"rowcacode2": str})
df = pd.read_csv("admin2.csv", dtype={"rowcacode2": str})
#with open("geojson-counties-fips.json") as response:
#with open("NER_adm02_feb2018.json") as response:
with open("NER_adm02_feb2018.json") as response:
counties = json.load(response)
fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.rowcacode2, z=df.urgence,
colorscale="Viridis", zmin=0, zmax=12,
marker_opacity=0.5, marker_line_width=0))
fig.update_layout(mapbox_style="carto-positron",
mapbox_zoom=5, mapbox_center = {"lat": 17.607789, "lon": 8.081666})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
app = dash.Dash()
app.layout = html.Div([
dcc.Graph(figure=fig),
])
app.run_server(debug=True, use_reloader=False)
loaddash() |
Partager