Hi,
Thanks for the great work!
I want to implement dropdown value interactive with tabs .It’s ok for adding new tab by using patch().append function.However, I just confuse how to delete tab when delete selected value in dropdown component?
Is there anyone have ideas about this question?
My code is as follows:
import dash
from dash import dcc, html, Patch
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
import pprint
import uuid
from dash.dependencies import Input, Output, State, ALL, MATCH
app = dash.Dash(__name__)
app.layout = html.Div([
html.Div(
[
dcc.Dropdown(
id='dropdown',
options=[
{'label': 'tab1', 'value': 'tab1'},
{'label': 'tab2', 'value': 'tab2'},
{'label': 'tab3', 'value': 'tab3'},
{'label': 'tab4', 'value': 'tab4'},
{'label': 'tab5', 'value': 'tab5'},
{'label': 'tab6', 'value': 'tab6'},
{'label': 'tab7', 'value': 'tab7'},
],
multi=True,
),
],
style={
'padding': '50px',
},
),
dcc.Store(id='tabs-store'),
html.Div(
[
dcc.Tabs(
id='tabs_example',
children=[]
)
],
style={
'padding': '50px',
},
id='tab_area_div'
),
html.Div(id='content')
])
@app.callback(
Output('tabs_example', 'children'),
Output('tabs_example', 'value'),
Input('dropdown', 'value'),
Input('tabs_example', 'children'),
prevent_initial_call=True
)
def test(value, tab_children):
tab_items = Patch()
for i in value:
if i not in [t['props']['value'] for t in tab_children]:
tab_items.append(
dcc.Tab(
label=i,
value=i,
children=html.Div([
html.H3('Tab content {}'.format(i))
])
)
)
return tab_items, i
if __name__ == '__main__':
app.run(debug=True, port='8070')
Thanks in advance