From 0d3a11ed7e129bc8169ef828c13cbdd8006c77fb Mon Sep 17 00:00:00 2001 From: Trevor Lyon Date: Mon, 6 Sep 2021 13:29:45 -0300 Subject: [PATCH] DASH choropleth-maps --- dash/choropleth-maps.jl | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 dash/choropleth-maps.jl diff --git a/dash/choropleth-maps.jl b/dash/choropleth-maps.jl new file mode 100644 index 0000000..5fbd6df --- /dev/null +++ b/dash/choropleth-maps.jl @@ -0,0 +1,46 @@ +using Dash +using DashCoreComponents +using DashHtmlComponents +using PlotlyJS, CSV, DataFrames + +app = dash(external_stylesheets=["https://codepen.io/chriddyp/pen/bWLwgP.css"]) + +df = dataset(DataFrame, "election") +candidates = unique(df.winner) +election_geo = dataset("election_geo") + +app.layout = html_div() do + html_p("Candidates"), + dcc_radioitems( + id="candidates", + options=[ + (label = x, value = x) + for x in candidates + ], + value=candidates[1], + labelStyle=(display = "inline-block",) + ), + dcc_graph(id="graph") +end + +callback!(app, Output("graph", "figure"), Input("candidates", "value")) do val + fig = plot( + df, + geojson=election_geo, + kind="choropleth", + range_color=[0,6500], + featureidkey="properties.district", + locations=:district, + z=df[!, val], + Layout( + geo_fitbounds="locations", + geo_projection_type="mercator", + geo_visible=false, + margin=(r = 0, t = 0, l = 0, b = 0) + ) + ) + + return fig +end + +run_server(app, "0.0.0.0", 8080)