如何以编程方式激活特定选项卡

Dav*_*jad 0 plotly-dash

我想在单击按钮时更改选项卡。如何切换标签页?

app.layout = html.Div(children=[
    html.H1(children=title),
    dcc.Markdown(header),
    dcc.Tabs(id='graphs', children=[
             dcc.Tab(label='Run', children=html.Div(children=form), value=10),
             dcc.Tab(id='result', label='Result', children=graphs, value=1)],
             value=10)])

@app.callback(Output('result', 'children'),
              [Input('run_btn', 'n_clicks')],
              inputs)
def call_simulation(clicks, *params):
    params = dict(zip(parameter_mask.keys(), params))
    if clicks is not None:
        print(params)
        try:
            simulation(params)
            SWITCH TO RESULT TAB
        except Exception as e:
            print(e)
            return html.Div(children=["The simulation produced an error with this particular parameterisation", str(type(e)), str(e)])

        return generate_graph_layout(newest_subdirectory('./result', ''))
    else:
        return html.Div()
Run Code Online (Sandbox Code Playgroud)

Ed *_*ton 5

您需要一个回调来将元素value的属性设置dcc.Tabsvalue要切换到的选项卡的属性。所以在你的例子中你需要类似的东西:

@app.callback(Output('graphs', 'value'),
          [Input('run_btn', 'n_clicks')],
          inputs)
def switch_tab(clicks, *params):
    if clicks is not None:
        return 1  # where 1 is the value of your results tab  
Run Code Online (Sandbox Code Playgroud)