如何使用python列表在Dash中填充下拉列表并在变量中获取其值?

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

我在Jupyter笔记本中有一个下拉列表,其中装有python列表中的值。我想在Plotly-Dash中复制相同的内容。Dropdown example

python dropdown plotly-dash
1个回答
0
投票

我在弄清楚的时候就知道了。将列表放入数据框。

df= pd.DataFrame({
'c' : list
})

为下拉菜单编码

dcc.Dropdown(
        id='dropdown',
        options=[
            {'label':i, 'value':i} for i in df['c'].unique()
        ],
    ),
html.Div(id='output')

回叫

@app.callback(Output('output', 'children'),
          [Input('dropdown', 'value')])
def update_output_1(value):
filtered_df = df[df['c'] == value]
return filtered_df.iloc[0]['c']
© www.soinside.com 2019 - 2024. All rights reserved.