【问题标题】:How to populate a dropdown in Dash using a python list and get it's value in a variable?如何使用 python 列表填充 Dash 中的下拉列表并在变量中获取它的值?
【发布时间】:2020-05-29 04:37:11
【问题描述】:

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

【问题讨论】:

    标签: python dropdown plotly-dash


    【解决方案1】:

    我在做的时候就想通了。将列表放入数据框中。

    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']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 2012-06-12
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 1970-01-01
      相关资源
      最近更新 更多