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

How to activate a particular tab programatically

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

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()

您需要回调将 dcc.Tabs 元素的 value 属性设置为您要切换到的选项卡的 value 属性。所以在你的例子中你需要这样的东西:

@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