Hi Dash gurus,
I got a questions in ‘options’ in dropdown box.
lets say I have a very long city name list to be contained in dropdown.
However, in the dropdown box, I want to only display the first three characters of the city name.
In documentation , I can do that manually, but I wonder if there is any handy way to do this (?)
Thanks
city_names = ["New York City", "Montreal", "San Francisco" ....... ]
from dash import Dash, dcc, html, Input, Output
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Dropdown(
id="dropdown",
className="inputbox-long",
options=[
{"label": "New ", "value": "New York City"},
{"label": "Mon", "value": "Montreal" },
{"label": "San", "value": "San Francisco"},
{"label": "Lon", "value": "London"},
{"label": "Wat", "value": "Waterloo" },
{"label": "Edi", "value": "Edinburgh"},
{"label": "Man", "value": "Manchester"},
{"label": "Sin", "value": "Singapore" },
{"label": "Par", "value": "Paris"},
{"label": "Mil", "value": "Milan"},
{"label": "Bar", "value": "Barcelona" },
{"label": "Sha", "value": "Shanghai"},
..........
],
placeholder="Select one or more",
multi=True,
),
html.Div(id="output"),
]
)
@app.callback(
Output("output", "children"), Input("dropdown", "value"),
)
def update(value):
return value
if __name__ == "__main__":
app.run_server(debug=True)