Hi everyone, I am trying to display a Mapbox Chororpleth figure on a Dash Graph object. but somehow, the figure does not show. Please could someone kindly point out how to fix the problem? thanks
The code is as simple as below:
import dash
import dash_html_components as html
import dash_core_components as dcc
app = dash.Dash()
def test_figure():
# example taken from plotly
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
import plotly.graph_objects as go
fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.fips, z=df.unemp,
colorscale="Viridis", zmin=0, zmax=12,
marker_opacity=0.5, marker_line_width=0))
fig.update_layout(mapbox_style="carto-positron",
mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
return fig
app.layout = html.Div([dcc.Graph(id='test-fig',figure = test_figure())])
if __name__ =='__main__':
app.run_server(debug=False)