TODAY learn how to bring Drag & Drop to Dash with Dashboard Engine. 🌠 Sign up for the live event!

Is it possible to have two labels corresponding to one value for options variable?

Greetings, as the title states, I would like add an extra label for each value in my option.

For example

OPTIONS = [
{'label': 'A', 'value': 'A'},
 {'label': 'AA', 'value': 'AA'},
 {'label': 'AAL', 'value': 'AAL'},
 {'label': 'AAP', 'value': 'AAP'}
]

to this:

OPTIONS = [
{'label': ['A', 'companyname'], 'value': 'A'},
 {'label': ['AA', 'companyname'], 'value': 'AA'},
 {'label': ['AAL', 'companyname'], 'value': 'AAL'},
 {'label': ['AAP', 'companyname'], 'value': 'AAP'}
]

This would make my dashboard much more user friendly, any would allow for people to search for either a company name or its stock symbol in my multi-dropdown.

Has anyone gotten this to work for them?

Hi andres1,
I do not have an answer to your specific question but two different solution for your problem.
One is put both values (ticker and Name) together like this example:

# Create a list of dict based on tickers and labels
dictlist = []
for index, row in stocks_info_df.iterrows():
     dictlist.append({'value':row['tickers'], 'label':row['labels']}) 
return dictlist

Extracted from this link:
https://towardsdatascience.com/value-investing-dashboard-with-python-beautiful-soup-and-dash-python-43002f6a97ca

The other is to present two different drowbaks, one for the ticker and the other for the Company name.
This one have an additional problem related that you can apply one result to the other because it will get a circular error.
I solved using one direction: the dropdown of the company name update the ‘value’ of the ticker and this value trigger the different callbacks of the app.
It has an issue that if you first use the Company name dropdown and then you change the ticker, the last company name is still shown in the dropdown, but do not affect the app.
You can see it here:

In this case I used an dcc.Input for the ticker instead of a dropdown but the process is the same.

How about just putting both company name and stock symbol in the label? The search in the dropdown looks for the text no matter the starting position so you could look for either.

OPTIONS = [
    {'label': 'Company1 (A)', 'value': 'A'},
    {'label': 'Company2 (AA)', 'value': 'AA'},
    {'label': 'Company3 (AAL)', 'value': 'AAL'},
    {'label': 'Company4 (AAP)', 'value': 'AAP'}
]

Yes, is like the first option I mentioned, but see that is better to join first the ticker and then the Name, to avoid the problem you have when you want to search a ticker you know eg. ‘X’ (United States Steel Corp), the search will give you all the Company names that has an ‘x’ in their names from the first listed name).
Also in both options additionally you can apply this solution for the issue mentioned: