I want when I select any region from the radio items, drop down list show the countries of that region. I share code below. Please make changes in the below code to get countries of specific region in the drop down list.
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
terr2 = pd.read_csv('modified_globalterrorismdb_0718dist.csv')
region = terr2['region_txt'].unique()
country = terr2['country_txt'].unique()
app = dash.Dash(__name__,)
app.layout = html.Div([
html.Div([
dcc.RadioItems(options=[
{'label': k, 'value': k} for k in region
], value='North America', id="radio_items"),
html.Label(['Select Country:'], style={'color': 'white'}),
dcc.Dropdown(id='w_countries',
multi=False,
clearable=True,
disabled=False,
style={'display': True},
value='Iraq',
placeholder='Select Countries',
options=[{'label': c, 'value': c}
for c in country])
], style={'margin-left': '5.4%', 'width': '20.4%', 'display': 'inline-block'}),
], style={'background-color': '#272B30'})
@app.callback(
Output('w_countries', 'options'),
Input('radio_items', 'value'))
def set_cities_options(selected_country):
return [{'label': i, 'value': i} for i in country[selected_country]]
if __name__ == '__main__':
app.run_server(debug=True)