在Python中使用plotly-Dash构建下拉菜单时出现问题

问题描述 投票:0回答:1

[代码](https://i.stack.imgur.com/NH1BZ.png) error

该错误表明选项内的元素必须是对象,但显然它们未被识别。 我是编程新手,但我在其他地方寻找答案但没有找到。我更喜欢更直接并尝试解决我的问题。

如果有人能帮助我,我将不胜感激,因为这个问题正在干扰我的学习。预先感谢

python plotly-dash
1个回答
0
投票

我认为您只是错误地将“标签”一词大写,而不是“标签”。只需复制此处的示例即可:

https://dash.plotly.com/dash-core-components/dropdown

from dash import Dash, dcc, html, Input, Output,callback

app = Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(
        options=[
            {'label': 'New York City', 'value': 'New York City'},
            {'label': 'Montreal', 'value': 'Montreal'},
            {'label': 'San Francisco', 'value': 'San Francisco'},
        ],
        value='Montreal'
    ),
    html.Div(id='dd-output-container')
])


@callback(
    Output('dd-output-container', 'children'),
    Input('demo-dropdown', 'value')
)
def update_output(value):
    return f'You have selected {value}'


if __name__ == '__main__':
    app.run(debug=True)
© www.soinside.com 2019 - 2024. All rights reserved.