I want when I select any country name from the drop down list, scattermapbox automatically zoom on the geographic location of that country. I share below code. Please make changes to get dynamic zoom on scattermapbox.
app.layout = html.Div([
html.Div([
dcc.Dropdown(id='w_countries',
multi=False,
clearable=True,
value='US',
placeholder='Select Countries',
options=[{'label': c, 'value': c}
for c in (covid_data['Country/Region'].unique())])
])
])
# Create scattermapbox chart
@app.callback(Output('map', 'figure'),
[Input('w_countries', 'value')])
def update_graph(w_countries):
covid_data_3 = covid_data.groupby(['Lat', 'Long', 'Country/Region'])[['confirmed', 'death', 'recovered', 'active']].max().reset_index()
return {
'data': [go.Scattermapbox(
lon=covid_data_3[covid_data_3['Country/Region'] == w_countries]['Long'],
lat=covid_data_3[covid_data_3['Country/Region'] == w_countries]['Lat'],
mode='markers',
marker=go.scattermapbox.Marker(
size=covid_data_3[covid_data_3['Country/Region'] == w_countries]['death'] / 50,
color=covid_data_3[covid_data_3['Country/Region'] == w_countries]['death'],
colorscale='hsv',
showscale=False,
sizemode='area',
opacity=0.3),
hoverinfo='text',
hovertext=
'<b>Country</b>: ' + covid_data_3[covid_data_3['Country/Region'] == w_countries]['Country/Region'].astype(str) + '<br>' +
'<b>Longitude</b>: ' + covid_data_3[covid_data_3['Country/Region'] == w_countries]['Long'].astype(str) + '<br>'
)],
'layout': go.Layout(
margin={"r": 0, "t": 0, "l": 0, "b": 0},
# width=1820,
# height=650,
hovermode='closest',
mapbox=dict(
accesstoken='',
center=go.layout.mapbox.Center(lat=36, lon=-5.4),
# style='open-street-map',
style='dark',
zoom=1.2
),
autosize=True,
)
}
if __name__ == '__main__':
app.run_server(debug=True)