How to select only label from a dict for graph title

I have a dictionary with labels and key as shown below.

country = pd.read_csv('assets/countries.csv')
country = country.set_index('Code')
country_options = [{'label': f'({cod}) {country.loc[cod, "Country"]} ',
                  'value': f'{cod}'} for cod in country.index]

[{‘label’: '(AFG) Afghanistan ', ‘value’: ‘AFG’}, {‘label’: '(ALB) Albania ', ‘value’: ‘ALB’}, {‘label’: '(DZA) Algeria '…

I also have a callback to update a graph and would like to add the title depending on the option selected from a dropdown list.

def update_graph(indi=indicator_options,coun=country_options):
df = indicator_select(coun, indi)
graph_content = dict(data=line_plot(df),
return graph_content

However, the title=coun will return me the 3 letter symbol (value) of the dict, but I need the label with the symbol and the name. Is it possible?

Hi @vspadotto, if your callback is triggered by the value of the Dropdown, you can keep the dropdown options in a list object and search for the list element for which the value is equal to the one in the callback, and use the corresponding label in the title.

1 Like

Great idea… thanks, it worked.