【问题标题】:Save selected value of dropdown and assign it by default in another dropdown / Duplicate dropdown保存下拉列表的选定值并在另一个下拉列表/重复下拉列表中默认分配它
【发布时间】:2021-10-16 06:48:58
【问题描述】:

我想知道是否可以保存下拉列表的选定值并默认将其放在具有相同值但位于另一个选项卡中的下拉列表中:

uriCounts 选项卡

 dcc.Tab(label='uriCounts', value = 'es_uricounts', children = [
    html.Div([
    html.Br(),
    html.H3("Choose uriCounts file version: "),
    dcc.Dropdown(id='uriCounts_dropdown',options=[
        {'label': 'Oct 1st 2016', 'value': 'Oct 1st 2016'},
        {'label': 'Oct 1st 2020', 'value': 'Oct 1st 2020'},
        {'label': 'May 25th 2021', 'value': 'May 25th 2021'},
        {'label': 'Jun 25th 2021', 'value': 'Jun 25th 2021'}], 
        placeholder="Version"),
     html.Br(),
    html.Div(id='uriCounts_container')
    ],style = {'margin-left': '3.2552083333333335vw', 'margin-right': '3.2552083333333335vw'})
     ], style = tab_style, selected_style = tab_selected_style)

pairCounts 选项卡

dcc.Tab(label='pairCounts', children = [
         html.Div([
            html.Br(),
    html.H3("Choose pairCounts file version: "),
    dcc.Dropdown(id='pairCounts_dropdown',options=[
         {'label': 'Oct 1st 2016', 'value': 'Oct 1st 2016'},
        {'label': 'Oct 1st 2020', 'value': 'Oct 1st 2020'},
        {'label': 'May 25th 2021', 'value': 'May 25th 2021'},
        {'label': 'Jun 25th 2021', 'value': 'Jun 25th 2021'}], 
        value=**uriCounts_value**),
     html.Br(),
    html.Div(id='pairCounts_container')
    ], style = {'margin-left': '3.2552083333333335vw', 'margin-right': '3.2552083333333335vw'})
      ], style = tab_style, selected_style = tab_selected_style)

当您在uriCounts 选项卡的下拉列表中选择一个值时,我希望pairCounts 选项卡的下拉列表具有该值。

如果它可以以相反的顺序完成,那就太好了:首先在pairCounts选项卡的下拉列表中选择一个值,然后在uriCounts选项卡的下拉列表中选择该值

希望你能帮我解决这个问题。提前致谢。

【问题讨论】:

    标签: plotly plotly-dash dashboard plotly-python


    【解决方案1】:

    @AnnMarieW 在Dash Community Forum 中给了我这个解决方案

    在回调中同步下拉菜单是一种可能的解决方案:

    @app.callback(
        Output('dropdown1', 'value'),
        Output('dropdown2', 'value'),
        Input('dropdown1', 'value'),
        Input('dropdown2', 'value'),
    )
    def sync_dropdowns(val1, val2):
        ctx = dash.callback_context
        input_id = ctx.triggered[0]['prop_id'].split('.')[0]
        if input_id == 'dropdown1':
            return dash.no_update, val1
        else:
            return val2, dash.no_update
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多