I am getting that ValueError when trying to use the dropdown with multiple selections (having 1 default value works fine); having two or more values results in the value error.
app.layout = html.Div([
html.H1(
children = "Visualizing Daily Occupancy Numbers at",
style = {'textAlign': 'center'}
),
# What the user clicks on
dcc.Dropdown(
id="select_sector",
options=list(dict(label=sector, value=sector) for sector in list(df['sector'].unique())),
value= 'Co-ed',
multi=True
),
html.Div(id='output_container', children=[]),
html.Br(),
dcc.Graph(id='my_line_graph', figure={}) # input graph type
])
# ------------------------------------------------------------------------------------------
# CONNECT THE PLOTLY GRAPHS WITH DASH COMPONENTS
@app.callback(
[Output(component_id='output_container', component_property='children'),
Output(component_id='my_line_graph', component_property='figure')],
[Input(component_id='select_sector', component_property='value')]
)
def update_graph(option_selected): # refers to Input component property value (^above)
print(option_selected)
print(type(option_selected))
container = "The sector chosen by the user was: {}".format(option_selected)
dff = df.copy()
dff = dff[dff['sector'] == option_selected]
# Plotly Express
fig = px.line(
data_frame=dff,
x='occupancy_date',
y='occupancy'
)
return container,fig ```