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 73
/
Copy pathapp_dropdown.py
189 lines (160 loc) · 5.43 KB
/
app_dropdown.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from collections import OrderedDict
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from textwrap import dedent
import dash_table
from index import app
from .utils import section_title
ID_PREFIX = "app_dropdown"
IDS = {
"dropdown": ID_PREFIX,
"dropdown-by-cell": '{}-row-by-cell'.format(ID_PREFIX)
}
df = pd.DataFrame(OrderedDict([
('climate',
['Sunny', 'Snowy', 'Sunny', 'Rainy']),
('temperature',
[13, 43, 50, 30]),
('city',
['NYC', 'Montreal', 'Miami', 'NYC'])
]))
df_per_row_dropdown = pd.DataFrame(OrderedDict([
('City',
['NYC', 'Montreal', 'Los Angeles']),
('Neighborhood',
['Brooklyn', 'Mile End', 'Venice']),
('Temperature (F)',
[70, 60, 90]),
]))
def layout():
return html.Div([
dcc.Markdown(dedent('''
The Dash table includes support for per-column and
per-cell dropdowns. In future releases, this will
be tightly integrated with a more formal typing system.
For now, use the dropdown renderer as a way to limit the
options available when editing the values with an editable table.
''')),
section_title('Dash Table with Per-Column Dropdowns'),
dash_table.DataTable(
id=IDS['dropdown'],
data=df.to_dict('rows'),
columns=[
{'id': 'climate', 'name': 'climate'},
{'id': 'temperature', 'name': 'temperature'},
{'id': 'city', 'name': 'city'},
],
editable=True,
column_static_dropdown=[
{
'id': 'climate',
'dropdown': [
{'label': i, 'value': i}
for i in df['climate'].unique()
]
},
{
'id': 'city',
'dropdown': [
{'label': i, 'value': i}
for i in df['city'].unique()
]
},
]
),
section_title('Dash Table with Per-Cell Dropdowns via Filtering UI'),
dash_table.DataTable(
id=IDS['dropdown-by-cell'],
data=df_per_row_dropdown.to_dict('rows'),
columns=[
{'id': c, 'name': c}
for c in df_per_row_dropdown.columns
],
editable=True,
column_conditional_dropdowns=[
{
'id': 'Neighborhood',
'dropdowns': [
{
'condition': 'City eq "NYC"',
'dropdown': [
{'label': i, 'value': i}
for i in [
'Brooklyn',
'Queens',
'Staten Island'
]
]
},
{
'condition': 'City eq "Montreal"',
'dropdown': [
{'label': i, 'value': i}
for i in [
'Mile End',
'Plateau',
'Hochelaga'
]
]
},
{
'condition': 'City eq "Los Angeles"',
'dropdown': [
{'label': i, 'value': i}
for i in [
'Venice',
'Hollywood',
'Los Feliz'
]
]
}
]
}
]
),
section_title('Dash Table with Per-Cell Dropdowns'),
html.Div('This example uses a deprecated API, `dropdown_properties`.'),
dash_table.DataTable(
id=IDS['dropdown-by-cell'],
data=df_per_row_dropdown.to_dict('rows'),
columns=[
{'id': c, 'name': c}
for c in df_per_row_dropdown.columns
],
editable=True,
dropdown_properties=[
{
'options': [
{'label': i, 'value': i}
for i in [
'Brooklyn',
'Queens',
'Staten Island'
]
]
},
{
'options': [
{'label': i, 'value': i}
for i in [
'Mile End',
'Plateau',
'Hochelaga'
]
]
},
{
'options': [
{'label': i, 'value': i}
for i in [
'Venice',
'Hollywood',
'Los Feliz'
]
]
},
]
),
])