我想在单击按钮时更改选项卡。如何切换标签?
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()
答案 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