-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
908c9df
commit 9f90669
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python mapping.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from dash import Dash, dcc, html, Input, Output | ||
import plotly.express as px | ||
import pandas as pd | ||
import geopandas as gpd | ||
|
||
gdf = pd.read_csv('https://raw.githubusercontent.com/LIRNEasia/d3-visualizations/master/resources/complete_data.csv') | ||
|
||
geo_json = gpd.read_file("https://raw.githubusercontent.com/LIRNEasia/d3-visualizations/master/resources/dsd_topology.json") | ||
|
||
|
||
geo_df = geo_json.merge(gdf, on="code_4").set_index('dsd_name_x') | ||
|
||
app = Dash(__name__) | ||
|
||
|
||
app.layout = html.Div([ | ||
html.H4('Choropleth map of Sri Lanka based on ASWSUM data'), | ||
html.P("Poverty category:"), | ||
dcc.RadioItems( | ||
id='candidate', | ||
options=["Severely Poor", "Poor", "Transient", "Vulnerable"], | ||
value="Poor", | ||
inline=True | ||
), | ||
dcc.Graph(id="graph"), | ||
]) | ||
|
||
|
||
@app.callback( | ||
Output("graph", "figure"), | ||
Input("candidate", "value")) | ||
def display_choropleth(candidate): | ||
|
||
fig = px.choropleth(geo_df, | ||
geojson=geo_df.geometry, | ||
color= candidate, | ||
locations=geo_df.index, | ||
#featureidkey= geo_df.index, | ||
projection="mercator",range_color=[0, 6500]) | ||
fig.update_geos(fitbounds="locations", visible=False) | ||
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0}) | ||
return fig | ||
|
||
|
||
|
||
app.run_server(host='0.0.0.0', port=8050) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dash==2.12.0 | ||
plotly==5.16.0 |