This repository was archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathdash-urls-hide-show-tabs.py
116 lines (97 loc) · 2.9 KB
/
dash-urls-hide-show-tabs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
tab_style = {
'color': '#0074D9',
'text-decoration': 'underline',
'margin': 30,
'cursor': 'pointer'
}
app.layout = html.Div([
dcc.Location(id='url'),
dcc.Link('Tab 1', href='/', style=tab_style),
dcc.Link('Tab 2', href='/tab-2', style=tab_style),
dcc.Link('Tab 3', href='/tab-3', style=tab_style),
html.Div([
# Tab 1
html.Div(
id='tab-1',
style={'display': 'none'},
children=[
html.H1('Tab 1'),
dcc.Dropdown(
id='dropdown-1',
options=[
{'label': 'Tab 1: {}'.format(i), 'value': i}
for i in ['A', 'B', 'C']
]
),
html.Div(id='display-1')
]
),
# Tab 2
html.Div(
id='tab-2',
style={'display': 'none'},
children=[
html.H1('Tab 2'),
dcc.Dropdown(
id='dropdown-2',
options=[
{'label': 'Tab 2: {}'.format(i), 'value': i}
for i in ['A', 'B', 'C']
]
),
html.Div(id='display-2')
]
),
# Tab 3
html.Div(
id='tab-3',
style={'display': 'none'},
children=[
html.H1('Tab 3'),
dcc.Dropdown(
id='dropdown-3',
options=[
{'label': 'Tab 3: {}'.format(i), 'value': i}
for i in ['A', 'B', 'C']
]
),
html.Div(id='display-3')
]
),
])
])
def generate_display_tab(tab):
def display_tab(pathname):
if tab == 'tab-1' and (pathname is None or pathname == '/'):
return {'display': 'block'}
elif pathname == '/{}'.format(tab):
return {'display': 'block'}
else:
return {'display': 'none'}
return display_tab
for tab in ['tab-1', 'tab-2', 'tab-3']:
app.callback(Output(tab, 'style'), [Input('url', 'pathname')])(
generate_display_tab(tab)
)
@app.callback(
Output('display-1', 'children'),
[Input('dropdown-1', 'value')])
def display_value(value):
return 'You have selected {}'.format(value)
@app.callback(
Output('display-2', 'children'),
[Input('dropdown-2', 'value')])
def display_value(value):
return 'You have selected {}'.format(value)
@app.callback(
Output('display-3', 'children'),
[Input('dropdown-3', 'value')])
def display_value(value):
return 'You have selected {}'.format(value)
if __name__ == '__main__':
app.run_server(debug=True)