forked from streamlit/streamlit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst_data_editor_config.py
418 lines (385 loc) · 14.3 KB
/
st_data_editor_config.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import random
import numpy as np
import pandas as pd
import streamlit as st
np.random.seed(0)
random.seed(0)
st.set_page_config(layout="wide")
# Generate a random dataframe
df = pd.DataFrame(
np.random.randn(5, 5),
columns=("col_%d" % i for i in range(5)),
)
st.header("Disabled parameter:")
st.data_editor(df, disabled=True)
st.data_editor(df, disabled=["col_4", "col_1"])
st.header("Hide index parameter:")
st.data_editor(df, hide_index=True)
st.data_editor(df, hide_index=False)
st.header("Column order parameter:")
st.data_editor(df, column_order=["col_4", "col_3", "col_0"])
st.header("Set column labels:")
st.data_editor(
df,
column_config={
"_index": "Index column",
"col_0": "Column 0",
"col_2": st.column_config.Column("Column 1"),
},
)
st.header("Hide columns:")
st.data_editor(df, column_config={"col_1": None, "col_3": {"hidden": True}})
st.header("Set column width:")
st.data_editor(
df,
column_config={
"col_0": st.column_config.Column(width="small"),
"col_1": st.column_config.Column(width="medium"),
"col_4": {"width": "large"},
},
)
st.header("Set help tooltips:")
st.caption("Hover over the column headers to see the tooltips.")
st.data_editor(
pd.DataFrame(
{
"col_0": ["a", "b", "c", None],
}
),
column_config={
"col_0": st.column_config.Column(help="This :red[is] a **tooltip** 🌟"),
"_index": {"help": "Index tooltip!"},
},
)
st.header("Text column:")
st.caption(
"Editing the first column should only allow 5 characters. The second column should only allow numerical characters."
)
st.data_editor(
pd.DataFrame(
{
"col_0": ["Hello World", "Lorem ipsum", "", None],
"col_1": ["1", "2", "3", None],
}
),
column_config={
"col_0": st.column_config.TextColumn(
"Text column",
width="medium",
help="This is a text column",
required=True,
disabled=False,
default="invalid",
max_chars=5,
),
"col_1": st.column_config.TextColumn(
validate="^[0-9]+$",
),
},
)
st.header("Number column:")
st.caption(
"Editing the first column should only allow to submit numbers between 0 and 5. And only a maximum of 2 decimals."
)
st.data_editor(
pd.DataFrame(
{
"col_0": [1, 2, 3, None],
"col_1": ["1", "2", "invalid", None],
}
),
column_config={
"col_0": st.column_config.NumberColumn(
"Number column",
width="medium",
help="This is a number column",
required=True,
disabled=False,
default=0,
min_value=5,
max_value=10,
step=0.01,
),
"col_1": st.column_config.NumberColumn(
format="%.2f%%",
),
},
)
st.header("Checkbox column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [True, False, False, None],
"col_1": ["yes", "no", "invalid", None],
}
),
column_config={
"col_0": st.column_config.CheckboxColumn(
"Checkbox column",
width="medium",
help="This is a checkbox column",
required=True,
disabled=False,
default=True,
),
"col_1": st.column_config.CheckboxColumn(),
},
)
st.header("Selectbox column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [1, 2, 3, None],
"col_1": ["a", "b", "c", None],
}
),
column_config={
"col_0": st.column_config.SelectboxColumn(
"Selectbox column",
width="medium",
help="This is a selectbox column",
required=True,
disabled=False,
default=True,
options=[1, 2, 3, 4, 5],
),
"col_1": st.column_config.SelectboxColumn(options=["a", "b", "c", "d"]),
},
)
st.header("Link column:")
st.caption(
"Editing the first column should only submitting values starting with http and a maximum of 50 characters."
)
st.data_editor(
pd.DataFrame(
{
"col_0": [
"https://streamlit.io/",
"https://docs.streamlit.io/",
"https://streamlit.io/gallery",
None,
],
"col_1": ["/a", "/b", "", None],
"col_2": [
"https://roadmap.streamlit.app",
"https://extras.streamlit.app",
"",
None,
],
}
),
column_config={
"col_0": st.column_config.LinkColumn(
"Link column",
width="medium",
help="This is a link column",
required=True,
disabled=False,
default="https://streamlit.io/",
max_chars=50,
validate=r"^http.*$",
),
"col_1": st.column_config.LinkColumn(),
"col_2": st.column_config.LinkColumn(
"Display text via Regex",
validate=r"^https://.*?\.streamlit\.app$",
display_text=r"https://(.*?)\.streamlit\.app",
),
},
)
st.header("Datetime column:")
st.caption(
"Editing the first column should only allow datetime values between 2021-01-01 and 2022-01-01."
)
st.data_editor(
pd.DataFrame(
{
"col_0": [
datetime.datetime(2021, 1, 1, 1, 0, 0, 123000),
datetime.datetime(2022, 1, 2, 2, 0, 0, 234000),
datetime.datetime(2023, 1, 3, 3, 0, 0, 345000),
None,
],
}
),
column_config={
"col_0": st.column_config.DatetimeColumn(
"Datetime column",
width="medium",
help="This is a datetime column",
required=True,
disabled=False,
default=datetime.datetime(2021, 1, 1, 1, 0, 0),
min_value=datetime.datetime(2021, 1, 1, 1, 0, 0),
max_value=datetime.datetime(2022, 1, 1, 1, 0, 0),
step=0.01,
format="YYYY-MM-DD HH:mm:ss.SSS",
),
},
)
st.header("Date column:")
st.caption(
"Editing the first column should only allow picking every second day and between 2021-01-01 and 2022-01-01."
)
st.data_editor(
pd.DataFrame(
{
"col_0": [
datetime.date(2021, 1, 1),
datetime.date(2022, 1, 2),
datetime.date(2023, 1, 3),
None,
],
}
),
column_config={
"col_0": st.column_config.DateColumn(
"Date column",
width="medium",
help="This is a date column",
required=True,
disabled=False,
default=datetime.date(2021, 1, 1),
min_value=datetime.date(2021, 1, 1),
max_value=datetime.date(2022, 1, 1),
step=2,
),
},
)
st.header("Time column:")
st.caption(
"Editing the first column should only allow datetime values between 01:02 and 01:03."
)
st.data_editor(
pd.DataFrame(
{
"col_0": [
datetime.time(1, 2, 0, 123000),
datetime.time(2, 3, 0, 234000),
datetime.time(3, 4, 0, 345000),
None,
]
}
),
column_config={
"col_0": st.column_config.TimeColumn(
"Time column",
width="medium",
help="This is a time column",
required=True,
disabled=False,
default=datetime.time(1, 2, 0),
min_value=datetime.time(1, 2, 0),
max_value=datetime.time(1, 3, 0),
step=datetime.timedelta(milliseconds=1),
),
},
)
st.header("Progress column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [0.1, 0.4, 1.1, None],
"col_1": ["200", "550", "1000", None],
}
),
column_config={
"col_0": st.column_config.ProgressColumn(
"Progress column",
width="medium",
help="This is a progress column",
),
"col_1": st.column_config.ProgressColumn(
format="$%f", min_value=0, max_value=1000
),
},
)
st.header("List column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [[1, 2], [2, 3, 4], [], None],
"col_1": ["a,b", "c,d,e", "", None],
}
),
column_config={
"col_0": st.column_config.ListColumn(
"List column",
width="medium",
help="This is a list column",
),
"col_1": st.column_config.ListColumn(),
},
)
st.header("Bar chart column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [[1, 5, 2], [2, 3, 5, -4, -5], [], None],
"col_1": ["1,2,3,4", "6, 5, 1, 10", "invalid", None],
}
),
column_config={
"col_0": st.column_config.BarChartColumn(
"Bar chart column",
width="medium",
help="This is a bar chart column",
y_min=-5,
y_max=5,
),
"col_1": st.column_config.BarChartColumn(),
},
)
st.header("Line chart column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [[1, 5, 2], [2, 3, 5, -4, -5], [], None],
"col_1": ["1,2,3,4", "6, 5, 1, 10", "invalid", None],
}
),
column_config={
"col_0": st.column_config.LineChartColumn(
"Line chart column",
width="medium",
help="This is a line chart column",
y_min=-5,
y_max=5,
),
"col_1": st.column_config.LineChartColumn(),
},
)
st.header("Image column:")
st.data_editor(
pd.DataFrame(
{
"col_0": [
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJYAAABSCAMAAACBpt1yAAAAwFBMVEVHcEyAhJWAhJUzNT97f4+AhJWAhJVtcH9WWWaAhJWAhJWAhJVCRFGAhJWAhJWAhJVVWGeAhJWAhJWAhJVVWGcmJzCAhJWAhJWAhJUmJzAmJzBVWGcmJzAmJzAmJzAmJzAmJzCAhJUmJzBVWGcmJzAmJzAmJzBVWGeAhJVVWGdVWGdVWGeAhJVVWGdVWGdVWGdvcoJVJ2WAhJVVWGcmJzBTVmVaXWx8f5B1eYlhZHNoa3tDRVI3OUQtLzhucoJMT13kXsyQAAAAMXRSTlMA+SYWE/ExBQvmfME1P7Uc9lhpjSdsTZ7cnETlsyP6xvHNg7XXV+bYq6NjTtR1yJLh8/IzCQAABHhJREFUaN7Nmut2mkAYRZGLIMQbRMFbvMQYkm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THJXrALzBToyFD8vVVoA72Jn0HMat9IXDn9K4EahSV+mLZuyL5rYUOY7YA/AGS3w2zml/N2QBcAc7/qa4La36ZEa3r0fc1UhX+Og4ogfABwxzNU7of+1oAvABe89opC08wxlcxRn7It+W8i89BuzMUnhepU+AHWONuwULlmYAx8TD/1X8HPbfSo/M2PE0ZaIqeRzBDMb6JQ7BbAF/sBnzt41VXeHN9fGjxJdn1bHBF0xx20KZyF3d7hn7jlKvz5bi7A3X1rsVvqqnarLYHg9N3XIDQqejlGJsKUrHWRs929LNYbctylpt3+VVVVnui+1uwBhAWrbb6xnGer13HKeTSvCCs1+vDaPnurYVgJjDcYDSr5GlEDN4J+V+EFEU23GCP4jBa7IcUKilOf4CgQRuuzC9EJcAAAAASUVORK5CYII=",
"data:image/svg+xml,%3Csvg width='301' height='165' viewBox='0 0 301 165' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M150.731 101.547L98.1387 73.7471L6.84674 25.4969C6.7634 25.4136 6.59674 25.4136 6.51341 25.4136C3.18007 23.8303 -0.236608 27.1636 1.0134 30.497L47.5302 149.139L47.5385 149.164C47.5885 149.281 47.6302 149.397 47.6802 149.514C49.5885 153.939 53.7552 156.672 58.2886 157.747C58.6719 157.831 58.9461 157.906 59.4064 157.998C59.8645 158.1 60.5052 158.239 61.0552 158.281C61.1469 158.289 61.2302 158.289 61.3219 158.297H61.3886C61.4552 158.306 61.5219 158.306 61.5886 158.314H61.6802C61.7386 158.322 61.8052 158.322 61.8636 158.322H61.9719C62.0386 158.331 62.1052 158.331 62.1719 158.331V158.331C121.084 164.754 180.519 164.754 239.431 158.331V158.331C240.139 158.331 240.831 158.297 241.497 158.231C241.714 158.206 241.922 158.181 242.131 158.156C242.156 158.147 242.189 158.147 242.214 158.139C242.356 158.122 242.497 158.097 242.639 158.072C242.847 158.047 243.056 158.006 243.264 157.964C243.681 157.872 243.87 157.806 244.436 157.611C245.001 157.417 245.94 157.077 246.527 156.794C247.115 156.511 247.522 156.239 248.014 155.931C248.622 155.547 249.201 155.155 249.788 154.715C250.041 154.521 250.214 154.397 250.397 154.222L250.297 154.164L150.731 101.547Z' fill='%23FF4B4B'/%3E%3Cpath d='M294.766 25.4981H294.683L203.357 73.7483L254.124 149.357L300.524 30.4981V30.3315C301.691 26.8314 298.108 23.6648 294.766 25.4981' fill='%237D353B'/%3E%3Cpath d='M155.598 2.55572C153.264 -0.852624 148.181 -0.852624 145.931 2.55572L98.1389 73.7477L150.731 101.548L250.398 154.222C251.024 153.609 251.526 153.012 252.056 152.381C252.806 151.456 253.506 150.465 254.123 149.356L203.356 73.7477L155.598 2.55572Z' fill='%23BD4043'/%3E%3C/svg%3E%0A",
"",
None,
],
}
),
column_config={
"col_0": st.column_config.ImageColumn(
"Image column",
width="medium",
help="This is a image column",
),
},
)