I need a Tabs component which is constructed from a list of names, where for each name a separate tab is created with the corresponding name as label and id. I need to have the generated tabs in separate divs which will then be populated with separate content.
Similarly to the example in the User Guide, I tried to output children of the Tabs component from a callback. This resulted in JavaScript Error: “Cannot read property disabled of undefined”.
Here is a simplified version of the code:
tabs_list = ['gen_tab1','gen_tab2']
def generate_tabs_html(available_tabs):
tabs_html = """
dcc.Tab(label='{}', id='{}', children=[
html.Div()
])""".format(available_tabs[0],available_tabs[0])
for i in range (1,len(available_tabs)):
tabs_html += """
dcc.Tab(label='{}', id='{}', children=[
html.Div()
])""".format(available_tabs[i],available_tabs[i])
return(tabs_html)
app.layout = html.Div([
dcc.Tabs(id="tabs")
],id='app-container')
@app.callback(
[dash.dependencies.Output('tabs', 'children') ],
[dash.dependencies.Input('login-button', 'n_clicks')])
def update_graph(button_clicks):
return generate_tabs_html(tabs_list)