I’m using dash-bootstrap-components (v1.4.1) Card component to display some labels (text) and dash-core-components (v2.0.0) Dropdowns. When I use html components for the layout of the card, the dropdown loads the values in df.CountyName.unique() at startup, as intended.
card_main = dbc.Card(
[
dbc.CardBody(
[
html.H4("Select a location to browse", className="card-title"),
# html.H6("Lesson 1:", className="card-subtitle"),
html.Div([
html.P("County", className="card-text"),
dcc.Dropdown(options=df.CountyName.unique(), id='county_chosen',
# options=[{'label': i, "value": i} for i in df.CountyName.unique()],
value='', clearable=False, style={"color": "#000000"}),
]),
html.P(
"Now choose the town you would like to browse.",
className="card-text mt-2",
),
dcc.Dropdown(options={}, id='town_chosen', clearable=False, style={"color": "#000000"})
# options=[{'label': 'town', 'value': 'town'}])
# dbc.Button("Press me", color="primary"),
# dbc.CardLink("GirlsWhoCode", href="https://girlswhocode.com/", target="_blank"),
]
),
],
color="dark", # https://bootswatch.com/default/ for more card colors
inverse=True, # change color of text (black or white)
outline=False, # True = remove the block colors from the background and header
)
When I use dash-bootstrap-components (v1.4.1) Row and Col for the layout, the dropdown doesn’t load the values, even though I can see that df.CountyName.unique() returns the expected values when in the debugger.
card_main = dbc.Card(
[
dbc.CardBody(
[
html.H5("Select a location to browse", className="card-title"),
# html.H6("Lesson 1:", className="card-subtitle"),
html.Div(
[
dbc.Row([
dbc.Col(dbc.Label("County", html_for="county_chosen", className="mt-1 ps-4"), width=1),
dbc.Col(dcc.Dropdown(id='county_chosen', options=df.CountyName.unique()), width=2)
]
),
dbc.Row([
dbc.Col(dbc.Label("Town", html_for="town_chosen", className="mt-1 ps-4"), width=1),
dbc.Col(dcc.Dropdown(id='town_chosen', options={}), width=7)
]
)
]
),
]
),
],
color="dark", # https://bootswatch.com/default/ for more card colors
inverse=True, # change color of text (black or white)
outline=False, # True = remove the block colors from the background and header
)
The card layout is the only thing different in the app (it’s the same app with 2 different cards I can switch between.
Seems like a bug…
Ultimately I want to have multiple labels and dropdowns in the same row, but haven’t figured out how to do that with straight HTML.
Sorry, I don’t know how to add the code so that it shows up properly formatted. I didn’t see an FAQ or other instructions. Can someone show me how so I can do it right next time?