Hi!
i have app. I can add new tabs dynamically (user passes title, and content - graph,textarea,datatable). How to write callback or callbacks for unlimited and unknown quantity of tabs? My code is below. Dash version:1.8.1 (without pattern-match callbacks)
Management page where you can add new tabs:
management_page= html.Div([
dcc.Input(id='name',placeholder='Type a name',type='text'),
dcc.Input(id='name1', placeholder='Type a name', type='text'),
html.Br(),
"Choose elements",
dcc.Dropdown(id='dropd',options=[
{'label': 'Graph', 'value': 'graph'},
{'label': 'Textarea', 'value': 'textarea'},
{'label': 'Datatable', 'value': 'dt'},
],
multi=True),
html.Button(id='button',children='Nazwa'),
html.Br(),
])
@app.callback(Output('tabs','children'),[Input('name','value'),Input('button','n_clicks'),Input('dropd','value')],[State('tabs','children')]
)
def addNew(val,click,drop_name,children):
ctx = dash.callback_context
if ctx.triggered[0]['prop_id'].split('.')[0] == u'button':
#pprint(drop_name[0])
tab = dcc.Tab(label=str(val), value=str(val))
tab_array.append(tab)
prop = nameChecker(drop_name[0])
tab_array_names[str(val)]=Tab(str(val),prop,click).page
children+=[tab]
pprint(children)
return children
This is my class tab with methods:
class Tab():
def __init__(self,name,prop,n_click):
self.name= name
self.type=prop
prop = nameChecker(prop,n_click)
self.page = html.Div(
[
html.H1('This'),
html.H2('is'),
html.H3('a page'),
prop,
]
)
def nameChecker(prop,n_click):
name_array = {
'Graph': dcc.Graph(id='Graph'),
'Textarea': dcc.Textarea(id='Textarea'),
'Datatable': dt.DataTable(id='Datatable')
}
arg = name_array[prop]
return arg
Scs with example - I added new tab ‘name1’ with textarea.
This is how ‘name1’ looks.
And second one ‘name2’ with Graph.
My question is: how to write callback or callbacks for all of them (I can have eg.10 tabs with graph, 2 with textarea, 15 with datatable). Is it possible? Please,help me - I can’t sleep