@chriddyp, just checking in to see if this was a bug you found? I’ve contintued to work on the issue and still haven’t found a solution. I’ve included my code within the comment with smaller example data in case that’s more useful than the repository I linked:
Code in Jupyter Notebook (again, this works fine and returns the choropleth map)
# Libraries
import pandas as pd
import plotly.express as px
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)
#Dataframe
df = pd.DataFrame(
{
"County": ['Andrews', 'Atascosa', 'Bee', 'Bexar', 'Brazoria'],
"fips": ['48003', '48013', '48025', '48029', '48039'],
"Tons Emitted": [2024.73, 42.63, 11.09, 1.02, 1585.57],
"Region": ['Texas', 'Texas', 'Texas', 'Texas', 'Texas'],
"Type": ['All', 'All', 'All', 'All', 'All']
})
#Choropleth map
fig = px.choropleth(df,
geojson=counties,
locations='fips',
color='Tons Emitted',
scope='usa')
fig.update_geos(fitbounds='locations')
fig.show()
Code for Dash App (this is executed in PyCharm)
#Libraries
import pandas as pd
import plotly.express as px
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 dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
df = pd.DataFrame(
{
"County": ['Andrews', 'Atascosa', 'Bee', 'Bexar', 'Brazoria'],
"fips": ['48003', '48013', '48025', '48029', '48039'],
"Tons Emitted": [2024.73, 42.63, 11.09, 1.02, 1585.57],
"Region": ['Texas', 'Texas', 'Texas', 'Texas', 'Texas'],
"Type": ['All', 'All', 'All', 'All', 'All']
})
# App Layout ------------
app.layout = html.Div([
html.H1("2019 Texas Emissions Event Database (STEERS)", style={'text-align': 'center'}),
dcc.Dropdown(id="slct_region",
options=[
{"label": "Texas", "value": "Texas"},
{"label": "Permian Basin", "value": "Permian Basin"},
{"label": "Gulf Coast", "value": "Gulf Coast"}],
multi=False,
value="Texas",
style={'width': "40%"}),
html.Br(),
dcc.Dropdown(id="slct_contam",
options=[
{"label": "All", "value": "All"},
{"label": "GHG", "value": "GHG"},
{"label": "HAP", "value": "HAP"},
{"label": "NOX", "value": "NOX"},
{"label": "Other", "value": "Other"},
{"label": "PM", "value": "PM"},
{"label": "SO2", "value": "SO2"},
{"label": "SOX", "value": "SOX"},
{"label": "TOX", "value": "TOX"},
{"label": "VOC", "value": "VOC"}],
multi=False,
value="All",
style={'width': "40%"}),
dcc.Graph(id='emission_map')
])
# Callback -----------
@app.callback(
Output('emission_map', 'figure'),
[Input('slct_region', 'value'),
Input('slct_contam', 'value')])
def update_fig2(region, contam):
dff3 = df.copy()
dff3a = dff3[(dff3['Region'] == region)]
dff3b = dff3a[dff3a['Type'] == contam]
fig2 = px.choropleth(data_frame=dff3b,
geojson=counties,
locations="fips",
color='Tons Emitted',
scope='usa'
)
fig2.update_geos(fitbounds="locations")
fig2.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
return fig2
# Execute app ---------------------
if __name__ == '__main__':
app.run_server(debug=True, )
Thanks again for looking into this