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

时间:2018-08-02 15:41:46

标签: 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()

1 个答案:

答案 0 :(得分:1)

您需要回调以将value元素的dcc.Tabs属性设置为要切换到的选项卡的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