streamlit-nightly 1.26.1.dev20230912__py2.py3-none-any.whl → 1.26.1.dev20230915__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. streamlit/elements/dataframe_selector.py +139 -158
  2. streamlit/elements/pyplot.py +1 -1
  3. streamlit/elements/widgets/button.py +14 -1
  4. streamlit/elements/widgets/number_input.py +25 -18
  5. streamlit/elements/widgets/selectbox.py +4 -3
  6. streamlit/elements/widgets/text_widgets.py +172 -73
  7. streamlit/proto/NumberInput_pb2.py +4 -4
  8. streamlit/proto/TextArea_pb2.py +2 -2
  9. streamlit/proto/TextInput_pb2.py +4 -4
  10. streamlit/runtime/metrics_util.py +9 -0
  11. streamlit/runtime/state/__init__.py +0 -1
  12. streamlit/runtime/state/session_state.py +2 -2
  13. streamlit/runtime/state/widgets.py +0 -4
  14. streamlit/static/asset-manifest.json +8 -8
  15. streamlit/static/index.html +1 -1
  16. streamlit/static/static/js/1451.76174eea.chunk.js +1 -0
  17. streamlit/static/static/js/{4436.0d12b4f4.chunk.js → 4436.9b8d7cb9.chunk.js} +1 -1
  18. streamlit/static/static/js/4666.29813cd1.chunk.js +1 -0
  19. streamlit/static/static/js/5379.acbf1a74.chunk.js +1 -0
  20. streamlit/static/static/js/7175.1af60fa9.chunk.js +1 -0
  21. streamlit/static/static/js/8691.9d96e187.chunk.js +1 -0
  22. streamlit/static/static/js/main.2ba402e0.js +2 -0
  23. streamlit/testing/element_tree.py +14 -12
  24. {streamlit_nightly-1.26.1.dev20230912.dist-info → streamlit_nightly-1.26.1.dev20230915.dist-info}/METADATA +1 -1
  25. {streamlit_nightly-1.26.1.dev20230912.dist-info → streamlit_nightly-1.26.1.dev20230915.dist-info}/RECORD +30 -30
  26. streamlit/static/static/js/1451.20b10c89.chunk.js +0 -1
  27. streamlit/static/static/js/4666.fe4ef587.chunk.js +0 -1
  28. streamlit/static/static/js/5379.ed613f3a.chunk.js +0 -1
  29. streamlit/static/static/js/7175.2ddee0f1.chunk.js +0 -1
  30. streamlit/static/static/js/8691.593dd822.chunk.js +0 -1
  31. streamlit/static/static/js/main.f88db55d.js +0 -2
  32. /streamlit/static/static/js/{main.f88db55d.js.LICENSE.txt → main.2ba402e0.js.LICENSE.txt} +0 -0
  33. {streamlit_nightly-1.26.1.dev20230912.data → streamlit_nightly-1.26.1.dev20230915.data}/scripts/streamlit.cmd +0 -0
  34. {streamlit_nightly-1.26.1.dev20230912.dist-info → streamlit_nightly-1.26.1.dev20230915.dist-info}/WHEEL +0 -0
  35. {streamlit_nightly-1.26.1.dev20230912.dist-info → streamlit_nightly-1.26.1.dev20230915.dist-info}/entry_points.txt +0 -0
  36. {streamlit_nightly-1.26.1.dev20230912.dist-info → streamlit_nightly-1.26.1.dev20230915.dist-info}/top_level.txt +0 -0
@@ -17,7 +17,7 @@ from __future__ import annotations
17
17
  import numbers
18
18
  from dataclasses import dataclass
19
19
  from textwrap import dedent
20
- from typing import TYPE_CHECKING, Union, cast, overload
20
+ from typing import Literal, Union, cast, overload
21
21
 
22
22
  import streamlit
23
23
  from streamlit.elements.form import current_form_id
@@ -32,7 +32,6 @@ from streamlit.proto.NumberInput_pb2 import NumberInput as NumberInputProto
32
32
  from streamlit.runtime.metrics_util import gather_metrics
33
33
  from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
34
34
  from streamlit.runtime.state import (
35
- DefaultValue,
36
35
  WidgetArgs,
37
36
  WidgetCallback,
38
37
  WidgetKwargs,
@@ -43,9 +42,6 @@ from streamlit.type_util import Key, LabelVisibility, maybe_raise_label_warnings
43
42
 
44
43
  Number = Union[int, float]
45
44
 
46
- if TYPE_CHECKING:
47
- from builtins import ellipsis
48
-
49
45
 
50
46
  @dataclass
51
47
  class NumberInputSerde:
@@ -73,7 +69,7 @@ class NumberInputMixin:
73
69
  label: str,
74
70
  min_value: Number | None = None,
75
71
  max_value: Number | None = None,
76
- value: ellipsis | Number = ...,
72
+ value: Number | Literal["min"] = "min",
77
73
  step: Number | None = None,
78
74
  format: str | None = None,
79
75
  key: Key | None = None,
@@ -82,6 +78,7 @@ class NumberInputMixin:
82
78
  args: WidgetArgs | None = None,
83
79
  kwargs: WidgetKwargs | None = None,
84
80
  *, # keyword-only arguments:
81
+ placeholder: str | None = None,
85
82
  disabled: bool = False,
86
83
  label_visibility: LabelVisibility = "visible",
87
84
  ) -> Number:
@@ -102,6 +99,7 @@ class NumberInputMixin:
102
99
  args: WidgetArgs | None = None,
103
100
  kwargs: WidgetKwargs | None = None,
104
101
  *, # keyword-only arguments:
102
+ placeholder: str | None = None,
105
103
  disabled: bool = False,
106
104
  label_visibility: LabelVisibility = "visible",
107
105
  ) -> Number | None:
@@ -113,7 +111,7 @@ class NumberInputMixin:
113
111
  label: str,
114
112
  min_value: Number | None = None,
115
113
  max_value: Number | None = None,
116
- value: ellipsis | Number | None = ...,
114
+ value: Number | Literal["min"] | None = "min",
117
115
  step: Number | None = None,
118
116
  format: str | None = None,
119
117
  key: Key | None = None,
@@ -122,6 +120,7 @@ class NumberInputMixin:
122
120
  args: WidgetArgs | None = None,
123
121
  kwargs: WidgetKwargs | None = None,
124
122
  *, # keyword-only arguments:
123
+ placeholder: str | None = None,
125
124
  disabled: bool = False,
126
125
  label_visibility: LabelVisibility = "visible",
127
126
  ) -> Number | None:
@@ -167,10 +166,11 @@ class NumberInputMixin:
167
166
  max_value : int, float, or None
168
167
  The maximum permitted value.
169
168
  If None, there will be no maximum.
170
- value : int, float, or None
171
- The value of this widget when it first renders. If ``None``, the widget
172
- will initialize empty and return ``None`` until the user provides input.
173
- Defaults to min_value, or 0.0 if min_value is None.
169
+ value : int, float, "min" or None
170
+ The value of this widget when it first renders. If ``None``, will initialize
171
+ empty and return ``None`` until the user provides input.
172
+ If "min" (default), will initialize with min_value, or 0.0 if
173
+ min_value is None.
174
174
  step : int, float, or None
175
175
  The stepping interval.
176
176
  Defaults to 1 if the value is an int, 0.01 otherwise.
@@ -192,6 +192,9 @@ class NumberInputMixin:
192
192
  An optional tuple of args to pass to the callback.
193
193
  kwargs : dict
194
194
  An optional dict of kwargs to pass to the callback.
195
+ placeholder : str or None
196
+ An optional string displayed when the number input is empty.
197
+ If None, no placeholder is displayed.
195
198
  disabled : bool
196
199
  An optional boolean, which disables the number input if set to
197
200
  True. The default is False. This argument can only be supplied by
@@ -223,7 +226,7 @@ class NumberInputMixin:
223
226
 
224
227
  >>> import streamlit as st
225
228
  >>>
226
- >>> number = st.number_input('Insert a number', value=None)
229
+ >>> number = st.number_input("Insert a number", value=None, placeholder="Type a number...")
227
230
  >>> st.write('The current number is ', number)
228
231
 
229
232
  .. output::
@@ -244,6 +247,7 @@ class NumberInputMixin:
244
247
  on_change=on_change,
245
248
  args=args,
246
249
  kwargs=kwargs,
250
+ placeholder=placeholder,
247
251
  disabled=disabled,
248
252
  label_visibility=label_visibility,
249
253
  ctx=ctx,
@@ -254,7 +258,7 @@ class NumberInputMixin:
254
258
  label: str,
255
259
  min_value: Number | None = None,
256
260
  max_value: Number | None = None,
257
- value: ellipsis | Number | None = ...,
261
+ value: Number | Literal["min"] | None = "min",
258
262
  step: Number | None = None,
259
263
  format: str | None = None,
260
264
  key: Key | None = None,
@@ -263,6 +267,7 @@ class NumberInputMixin:
263
267
  args: WidgetArgs | None = None,
264
268
  kwargs: WidgetKwargs | None = None,
265
269
  *, # keyword-only arguments:
270
+ placeholder: str | None = None,
266
271
  disabled: bool = False,
267
272
  label_visibility: LabelVisibility = "visible",
268
273
  ctx: ScriptRunContext | None = None,
@@ -270,7 +275,7 @@ class NumberInputMixin:
270
275
  key = to_key(key)
271
276
  check_callback_rules(self.dg, on_change)
272
277
  check_session_state_rules(
273
- default_value=None if value is DefaultValue else value, key=key
278
+ default_value=value if value != "min" else None, key=key
274
279
  )
275
280
  maybe_raise_label_warnings(label, label_visibility)
276
281
 
@@ -285,6 +290,7 @@ class NumberInputMixin:
285
290
  format=format,
286
291
  key=key,
287
292
  help=help,
293
+ placeholder=None if placeholder is None else str(placeholder),
288
294
  form_id=current_form_id(self.dg),
289
295
  page=ctx.page_script_hash if ctx else None,
290
296
  )
@@ -293,13 +299,12 @@ class NumberInputMixin:
293
299
  number_input_args = [min_value, max_value, value, step]
294
300
 
295
301
  int_args = all(
296
- isinstance(a, (numbers.Integral, type(None), type(DefaultValue)))
302
+ isinstance(a, (numbers.Integral, type(None), str))
297
303
  for a in number_input_args
298
304
  )
299
305
 
300
306
  float_args = all(
301
- isinstance(a, (float, type(None), type(DefaultValue)))
302
- for a in number_input_args
307
+ isinstance(a, (float, type(None), str)) for a in number_input_args
303
308
  )
304
309
 
305
310
  if not int_args and not float_args:
@@ -311,7 +316,7 @@ class NumberInputMixin:
311
316
  f"\n`step` has {type(step).__name__} type."
312
317
  )
313
318
 
314
- if value is DefaultValue:
319
+ if value == "min":
315
320
  if min_value is not None:
316
321
  value = min_value
317
322
  elif int_args and float_args:
@@ -410,6 +415,8 @@ class NumberInputMixin:
410
415
  number_input_proto.label = label
411
416
  if value is not None:
412
417
  number_input_proto.default = value
418
+ if placeholder is not None:
419
+ number_input_proto.placeholder = str(placeholder)
413
420
  number_input_proto.form_id = current_form_id(self.dg)
414
421
  number_input_proto.disabled = disabled
415
422
  number_input_proto.label_visibility.value = get_label_visibility_proto_value(
@@ -84,7 +84,7 @@ class SelectboxMixin:
84
84
  args: WidgetArgs | None = None,
85
85
  kwargs: WidgetKwargs | None = None,
86
86
  *, # keyword-only arguments:
87
- placeholder: str = "Select...",
87
+ placeholder: str = "Choose an option",
88
88
  disabled: bool = False,
89
89
  label_visibility: LabelVisibility = "visible",
90
90
  ) -> T | None:
@@ -142,7 +142,8 @@ class SelectboxMixin:
142
142
  kwargs : dict
143
143
  An optional dict of kwargs to pass to the callback.
144
144
  placeholder : str
145
- A string to display when no options are selected. Defaults to 'Select...'.
145
+ A string to display when no options are selected.
146
+ Defaults to 'Choose an option'.
146
147
  disabled : bool
147
148
  An optional boolean, which disables the selectbox if set to True.
148
149
  The default is False. This argument can only be supplied by keyword.
@@ -218,7 +219,7 @@ class SelectboxMixin:
218
219
  args: WidgetArgs | None = None,
219
220
  kwargs: WidgetKwargs | None = None,
220
221
  *, # keyword-only arguments:
221
- placeholder: str = "Select...",
222
+ placeholder: str = "Choose an option",
222
223
  disabled: bool = False,
223
224
  label_visibility: LabelVisibility = "visible",
224
225
  ctx: ScriptRunContext | None = None,
@@ -12,9 +12,11 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from __future__ import annotations
16
+
15
17
  from dataclasses import dataclass
16
18
  from textwrap import dedent
17
- from typing import Optional, cast
19
+ from typing import cast, overload
18
20
 
19
21
  from typing_extensions import Literal
20
22
 
@@ -48,45 +50,85 @@ from streamlit.type_util import (
48
50
 
49
51
  @dataclass
50
52
  class TextInputSerde:
51
- value: SupportsStr
53
+ value: str | None
52
54
 
53
- def deserialize(self, ui_value: Optional[str], widget_id: str = "") -> str:
54
- return str(ui_value if ui_value is not None else self.value)
55
+ def deserialize(self, ui_value: str | None, widget_id: str = "") -> str | None:
56
+ return ui_value if ui_value is not None else self.value
55
57
 
56
- def serialize(self, v: str) -> str:
58
+ def serialize(self, v: str | None) -> str | None:
57
59
  return v
58
60
 
59
61
 
60
62
  @dataclass
61
63
  class TextAreaSerde:
62
- value: SupportsStr
64
+ value: str | None
63
65
 
64
- def deserialize(self, ui_value: Optional[str], widget_id: str = "") -> str:
65
- return str(ui_value if ui_value is not None else self.value)
66
+ def deserialize(self, ui_value: str | None, widget_id: str = "") -> str | None:
67
+ return ui_value if ui_value is not None else self.value
66
68
 
67
- def serialize(self, v: str) -> str:
69
+ def serialize(self, v: str | None) -> str | None:
68
70
  return v
69
71
 
70
72
 
71
73
  class TextWidgetsMixin:
72
- @gather_metrics("text_input")
74
+ @overload
73
75
  def text_input(
74
76
  self,
75
77
  label: str,
76
- value: SupportsStr = "",
77
- max_chars: Optional[int] = None,
78
- key: Optional[Key] = None,
78
+ value: str = "",
79
+ max_chars: int | None = None,
80
+ key: Key | None = None,
79
81
  type: Literal["default", "password"] = "default",
80
- help: Optional[str] = None,
81
- autocomplete: Optional[str] = None,
82
- on_change: Optional[WidgetCallback] = None,
83
- args: Optional[WidgetArgs] = None,
84
- kwargs: Optional[WidgetKwargs] = None,
82
+ help: str | None = None,
83
+ autocomplete: str | None = None,
84
+ on_change: WidgetCallback | None = None,
85
+ args: WidgetArgs | None = None,
86
+ kwargs: WidgetKwargs | None = None,
85
87
  *, # keyword-only arguments:
86
- placeholder: Optional[str] = None,
88
+ placeholder: str | None = None,
87
89
  disabled: bool = False,
88
90
  label_visibility: LabelVisibility = "visible",
89
91
  ) -> str:
92
+ pass
93
+
94
+ @overload
95
+ def text_input(
96
+ self,
97
+ label: str,
98
+ value: SupportsStr | None = None,
99
+ max_chars: int | None = None,
100
+ key: Key | None = None,
101
+ type: Literal["default", "password"] = "default",
102
+ help: str | None = None,
103
+ autocomplete: str | None = None,
104
+ on_change: WidgetCallback | None = None,
105
+ args: WidgetArgs | None = None,
106
+ kwargs: WidgetKwargs | None = None,
107
+ *, # keyword-only arguments:
108
+ placeholder: str | None = None,
109
+ disabled: bool = False,
110
+ label_visibility: LabelVisibility = "visible",
111
+ ) -> str | None:
112
+ pass
113
+
114
+ @gather_metrics("text_input")
115
+ def text_input(
116
+ self,
117
+ label: str,
118
+ value: str | SupportsStr | None = "",
119
+ max_chars: int | None = None,
120
+ key: Key | None = None,
121
+ type: Literal["default", "password"] = "default",
122
+ help: str | None = None,
123
+ autocomplete: str | None = None,
124
+ on_change: WidgetCallback | None = None,
125
+ args: WidgetArgs | None = None,
126
+ kwargs: WidgetKwargs | None = None,
127
+ *, # keyword-only arguments:
128
+ placeholder: str | None = None,
129
+ disabled: bool = False,
130
+ label_visibility: LabelVisibility = "visible",
131
+ ) -> str | None:
90
132
  r"""Display a single-line text input widget.
91
133
 
92
134
  Parameters
@@ -117,9 +159,10 @@ class TextWidgetsMixin:
117
159
  For accessibility reasons, you should never set an empty label (label="")
118
160
  but hide it with label_visibility if needed. In the future, we may disallow
119
161
  empty labels by raising an exception.
120
- value : object
162
+ value : object or None
121
163
  The text value of this widget when it first renders. This will be
122
- cast to str internally.
164
+ cast to str internally. If ``None``, will initialize empty and
165
+ return ``None`` until the user provides input. Defaults to empty string.
123
166
  max_chars : int or None
124
167
  Max number of characters allowed in text input.
125
168
  key : str or int
@@ -158,8 +201,9 @@ class TextWidgetsMixin:
158
201
 
159
202
  Returns
160
203
  -------
161
- str
162
- The current value of the text input widget.
204
+ str or None
205
+ The current value of the text input widget or ``None`` if no value has been
206
+ provided by the user.
163
207
 
164
208
  Example
165
209
  -------
@@ -194,32 +238,35 @@ class TextWidgetsMixin:
194
238
  def _text_input(
195
239
  self,
196
240
  label: str,
197
- value: SupportsStr = "",
198
- max_chars: Optional[int] = None,
199
- key: Optional[Key] = None,
241
+ value: SupportsStr | None = "",
242
+ max_chars: int | None = None,
243
+ key: Key | None = None,
200
244
  type: str = "default",
201
- help: Optional[str] = None,
202
- autocomplete: Optional[str] = None,
203
- on_change: Optional[WidgetCallback] = None,
204
- args: Optional[WidgetArgs] = None,
205
- kwargs: Optional[WidgetKwargs] = None,
245
+ help: str | None = None,
246
+ autocomplete: str | None = None,
247
+ on_change: WidgetCallback | None = None,
248
+ args: WidgetArgs | None = None,
249
+ kwargs: WidgetKwargs | None = None,
206
250
  *, # keyword-only arguments:
207
- placeholder: Optional[str] = None,
251
+ placeholder: str | None = None,
208
252
  disabled: bool = False,
209
253
  label_visibility: LabelVisibility = "visible",
210
- ctx: Optional[ScriptRunContext] = None,
211
- ) -> str:
254
+ ctx: ScriptRunContext | None = None,
255
+ ) -> str | None:
212
256
  key = to_key(key)
213
257
  check_callback_rules(self.dg, on_change)
214
258
  check_session_state_rules(default_value=None if value == "" else value, key=key)
215
259
 
216
260
  maybe_raise_label_warnings(label, label_visibility)
217
261
 
262
+ # Make sure value is always string or None:
263
+ value = str(value) if value is not None else None
264
+
218
265
  id = compute_widget_id(
219
266
  "text_input",
220
267
  user_key=key,
221
268
  label=label,
222
- value=str(value),
269
+ value=value,
223
270
  max_chars=max_chars,
224
271
  key=key,
225
272
  type=type,
@@ -233,7 +280,8 @@ class TextWidgetsMixin:
233
280
  text_input_proto = TextInputProto()
234
281
  text_input_proto.id = id
235
282
  text_input_proto.label = label
236
- text_input_proto.default = str(value)
283
+ if value is not None:
284
+ text_input_proto.default = value
237
285
  text_input_proto.form_id = current_form_id(self.dg)
238
286
  text_input_proto.disabled = disabled
239
287
  text_input_proto.label_visibility.value = get_label_visibility_proto_value(
@@ -280,29 +328,68 @@ class TextWidgetsMixin:
280
328
  )
281
329
 
282
330
  if widget_state.value_changed:
283
- text_input_proto.value = widget_state.value
331
+ if widget_state.value is not None:
332
+ text_input_proto.value = widget_state.value
284
333
  text_input_proto.set_value = True
285
334
 
286
335
  self.dg._enqueue("text_input", text_input_proto)
287
336
  return widget_state.value
288
337
 
289
- @gather_metrics("text_area")
338
+ @overload
290
339
  def text_area(
291
340
  self,
292
341
  label: str,
293
- value: SupportsStr = "",
294
- height: Optional[int] = None,
295
- max_chars: Optional[int] = None,
296
- key: Optional[Key] = None,
297
- help: Optional[str] = None,
298
- on_change: Optional[WidgetCallback] = None,
299
- args: Optional[WidgetArgs] = None,
300
- kwargs: Optional[WidgetKwargs] = None,
342
+ value: str = "",
343
+ height: int | None = None,
344
+ max_chars: int | None = None,
345
+ key: Key | None = None,
346
+ help: str | None = None,
347
+ on_change: WidgetCallback | None = None,
348
+ args: WidgetArgs | None = None,
349
+ kwargs: WidgetKwargs | None = None,
301
350
  *, # keyword-only arguments:
302
- placeholder: Optional[str] = None,
351
+ placeholder: str | None = None,
303
352
  disabled: bool = False,
304
353
  label_visibility: LabelVisibility = "visible",
305
354
  ) -> str:
355
+ pass
356
+
357
+ @overload
358
+ def text_area(
359
+ self,
360
+ label: str,
361
+ value: SupportsStr | None = None,
362
+ height: int | None = None,
363
+ max_chars: int | None = None,
364
+ key: Key | None = None,
365
+ help: str | None = None,
366
+ on_change: WidgetCallback | None = None,
367
+ args: WidgetArgs | None = None,
368
+ kwargs: WidgetKwargs | None = None,
369
+ *, # keyword-only arguments:
370
+ placeholder: str | None = None,
371
+ disabled: bool = False,
372
+ label_visibility: LabelVisibility = "visible",
373
+ ) -> str | None:
374
+ pass
375
+
376
+ @gather_metrics("text_area")
377
+ def text_area(
378
+ self,
379
+ label: str,
380
+ value: str | SupportsStr | None = "",
381
+ height: int | None = None,
382
+ max_chars: int | None = None,
383
+ key: Key | None = None,
384
+ help: str | None = None,
385
+ on_change: WidgetCallback | None = None,
386
+ args: WidgetArgs | None = None,
387
+ kwargs: WidgetKwargs | None = None,
388
+ *, # keyword-only arguments:
389
+ placeholder: str | None = None,
390
+ disabled: bool = False,
391
+ label_visibility: LabelVisibility = "visible",
392
+ ) -> str | None:
306
393
  r"""Display a multi-line text input widget.
307
394
 
308
395
  Parameters
@@ -333,9 +420,10 @@ class TextWidgetsMixin:
333
420
  For accessibility reasons, you should never set an empty label (label="")
334
421
  but hide it with label_visibility if needed. In the future, we may disallow
335
422
  empty labels by raising an exception.
336
- value : object
423
+ value : object or None
337
424
  The text value of this widget when it first renders. This will be
338
- cast to str internally.
425
+ cast to str internally. If ``None``, will initialize empty and
426
+ return ``None`` until the user provides input. Defaults to empty string.
339
427
  height : int or None
340
428
  Desired height of the UI element expressed in pixels. If None, a
341
429
  default height is used.
@@ -368,21 +456,28 @@ class TextWidgetsMixin:
368
456
 
369
457
  Returns
370
458
  -------
371
- str
372
- The current value of the text input widget.
459
+ str or None
460
+ The current value of the text area widget or ``None`` if no value has been
461
+ provided by the user.
373
462
 
374
463
  Example
375
464
  -------
376
465
  >>> import streamlit as st
377
466
  >>>
378
- >>> txt = st.text_area('Text to analyze', '''
379
- ... It was the best of times, it was the worst of times, it was
380
- ... the age of wisdom, it was the age of foolishness, it was
381
- ... the epoch of belief, it was the epoch of incredulity, it
382
- ... was the season of Light, it was the season of Darkness, it
383
- ... was the spring of hope, it was the winter of despair, (...)
384
- ... ''')
385
- >>> st.write('Sentiment:', run_sentiment_analysis(txt))
467
+ >>> txt = st.text_area(
468
+ ... "Text to analyze",
469
+ ... "It was the best of times, it was the worst of times, it was the age of "
470
+ ... "wisdom, it was the age of foolishness, it was the epoch of belief, it "
471
+ ... "was the epoch of incredulity, it was the season of Light, it was the "
472
+ ... "season of Darkness, it was the spring of hope, it was the winter of "
473
+ ... "despair, (...)",
474
+ ... )
475
+ >>>
476
+ >>> st.write(f'You wrote {len(txt)} characters.')
477
+
478
+ .. output::
479
+ https://doc-text-area.streamlit.app/
480
+ height: 300px
386
481
 
387
482
  """
388
483
  ctx = get_script_run_ctx()
@@ -405,31 +500,33 @@ class TextWidgetsMixin:
405
500
  def _text_area(
406
501
  self,
407
502
  label: str,
408
- value: SupportsStr = "",
409
- height: Optional[int] = None,
410
- max_chars: Optional[int] = None,
411
- key: Optional[Key] = None,
412
- help: Optional[str] = None,
413
- on_change: Optional[WidgetCallback] = None,
414
- args: Optional[WidgetArgs] = None,
415
- kwargs: Optional[WidgetKwargs] = None,
503
+ value: SupportsStr | None = "",
504
+ height: int | None = None,
505
+ max_chars: int | None = None,
506
+ key: Key | None = None,
507
+ help: str | None = None,
508
+ on_change: WidgetCallback | None = None,
509
+ args: WidgetArgs | None = None,
510
+ kwargs: WidgetKwargs | None = None,
416
511
  *, # keyword-only arguments:
417
- placeholder: Optional[str] = None,
512
+ placeholder: str | None = None,
418
513
  disabled: bool = False,
419
514
  label_visibility: LabelVisibility = "visible",
420
- ctx: Optional[ScriptRunContext] = None,
421
- ) -> str:
515
+ ctx: ScriptRunContext | None = None,
516
+ ) -> str | None:
422
517
  key = to_key(key)
423
518
  check_callback_rules(self.dg, on_change)
424
519
  check_session_state_rules(default_value=None if value == "" else value, key=key)
425
520
 
426
521
  maybe_raise_label_warnings(label, label_visibility)
427
522
 
523
+ value = str(value) if value is not None else None
524
+
428
525
  id = compute_widget_id(
429
526
  "text_area",
430
527
  user_key=key,
431
528
  label=label,
432
- value=str(value),
529
+ value=value,
433
530
  height=height,
434
531
  max_chars=max_chars,
435
532
  key=key,
@@ -442,7 +539,8 @@ class TextWidgetsMixin:
442
539
  text_area_proto = TextAreaProto()
443
540
  text_area_proto.id = id
444
541
  text_area_proto.label = label
445
- text_area_proto.default = str(value)
542
+ if value is not None:
543
+ text_area_proto.default = value
446
544
  text_area_proto.form_id = current_form_id(self.dg)
447
545
  text_area_proto.disabled = disabled
448
546
  text_area_proto.label_visibility.value = get_label_visibility_proto_value(
@@ -475,7 +573,8 @@ class TextWidgetsMixin:
475
573
  )
476
574
 
477
575
  if widget_state.value_changed:
478
- text_area_proto.value = widget_state.value
576
+ if widget_state.value is not None:
577
+ text_area_proto.value = widget_state.value
479
578
  text_area_proto.set_value = True
480
579
 
481
580
  self.dg._enqueue("text_area", text_area_proto)
@@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
14
14
  from streamlit.proto import LabelVisibilityMessage_pb2 as streamlit_dot_proto_dot_LabelVisibilityMessage__pb2
15
15
 
16
16
 
17
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n!streamlit/proto/NumberInput.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\xa7\x03\n\x0bNumberInput\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x03 \x01(\t\x12\x0e\n\x06\x66ormat\x18\x08 \x01(\t\x12\x0f\n\x07has_min\x18\x0b \x01(\x08\x12\x0f\n\x07has_max\x18\x0c \x01(\x08\x12(\n\tdata_type\x18\r \x01(\x0e\x32\x15.NumberInput.DataType\x12\x14\n\x07\x64\x65\x66\x61ult\x18\x0e \x01(\x01H\x00\x88\x01\x01\x12\x0c\n\x04step\x18\x0f \x01(\x01\x12\x0b\n\x03min\x18\x10 \x01(\x01\x12\x0b\n\x03max\x18\x11 \x01(\x01\x12\x0c\n\x04help\x18\x12 \x01(\t\x12\x12\n\x05value\x18\x13 \x01(\x01H\x01\x88\x01\x01\x12\x11\n\tset_value\x18\x14 \x01(\x08\x12\x10\n\x08\x64isabled\x18\x15 \x01(\x08\x12\x31\n\x10label_visibility\x18\x16 \x01(\x0b\x32\x17.LabelVisibilityMessage\"\x1e\n\x08\x44\x61taType\x12\x07\n\x03INT\x10\x00\x12\t\n\x05\x46LOAT\x10\x01\x42\n\n\x08_defaultB\x08\n\x06_valueJ\x04\x08\x04\x10\x05J\x04\x08\x05\x10\x06J\x04\x08\x06\x10\x07J\x04\x08\x07\x10\x08J\x04\x08\t\x10\nJ\x04\x08\n\x10\x0b\x62\x06proto3')
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n!streamlit/proto/NumberInput.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\xbc\x03\n\x0bNumberInput\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x03 \x01(\t\x12\x0e\n\x06\x66ormat\x18\x08 \x01(\t\x12\x0f\n\x07has_min\x18\x0b \x01(\x08\x12\x0f\n\x07has_max\x18\x0c \x01(\x08\x12(\n\tdata_type\x18\r \x01(\x0e\x32\x15.NumberInput.DataType\x12\x14\n\x07\x64\x65\x66\x61ult\x18\x0e \x01(\x01H\x00\x88\x01\x01\x12\x0c\n\x04step\x18\x0f \x01(\x01\x12\x0b\n\x03min\x18\x10 \x01(\x01\x12\x0b\n\x03max\x18\x11 \x01(\x01\x12\x0c\n\x04help\x18\x12 \x01(\t\x12\x12\n\x05value\x18\x13 \x01(\x01H\x01\x88\x01\x01\x12\x11\n\tset_value\x18\x14 \x01(\x08\x12\x10\n\x08\x64isabled\x18\x15 \x01(\x08\x12\x31\n\x10label_visibility\x18\x16 \x01(\x0b\x32\x17.LabelVisibilityMessage\x12\x13\n\x0bplaceholder\x18\x17 \x01(\t\"\x1e\n\x08\x44\x61taType\x12\x07\n\x03INT\x10\x00\x12\t\n\x05\x46LOAT\x10\x01\x42\n\n\x08_defaultB\x08\n\x06_valueJ\x04\x08\x04\x10\x05J\x04\x08\x05\x10\x06J\x04\x08\x06\x10\x07J\x04\x08\x07\x10\x08J\x04\x08\t\x10\nJ\x04\x08\n\x10\x0b\x62\x06proto3')
18
18
 
19
19
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
20
20
  _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'streamlit.proto.NumberInput_pb2', globals())
@@ -22,7 +22,7 @@ if _descriptor._USE_C_DESCRIPTORS == False:
22
22
 
23
23
  DESCRIPTOR._options = None
24
24
  _NUMBERINPUT._serialized_start=84
25
- _NUMBERINPUT._serialized_end=507
26
- _NUMBERINPUT_DATATYPE._serialized_start=419
27
- _NUMBERINPUT_DATATYPE._serialized_end=449
25
+ _NUMBERINPUT._serialized_end=528
26
+ _NUMBERINPUT_DATATYPE._serialized_start=440
27
+ _NUMBERINPUT_DATATYPE._serialized_end=470
28
28
  # @@protoc_insertion_point(module_scope)
@@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
14
14
  from streamlit.proto import LabelVisibilityMessage_pb2 as streamlit_dot_proto_dot_LabelVisibilityMessage__pb2
15
15
 
16
16
 
17
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1estreamlit/proto/TextArea.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\xf4\x01\n\x08TextArea\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65\x66\x61ult\x18\x03 \x01(\t\x12\x0e\n\x06height\x18\x04 \x01(\r\x12\x11\n\tmax_chars\x18\x05 \x01(\r\x12\x0c\n\x04help\x18\x06 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x07 \x01(\t\x12\r\n\x05value\x18\x08 \x01(\t\x12\x11\n\tset_value\x18\t \x01(\x08\x12\x13\n\x0bplaceholder\x18\n \x01(\t\x12\x10\n\x08\x64isabled\x18\x0b \x01(\x08\x12\x31\n\x10label_visibility\x18\x0c \x01(\x0b\x32\x17.LabelVisibilityMessageb\x06proto3')
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1estreamlit/proto/TextArea.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\x94\x02\n\x08TextArea\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x14\n\x07\x64\x65\x66\x61ult\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x0e\n\x06height\x18\x04 \x01(\r\x12\x11\n\tmax_chars\x18\x05 \x01(\r\x12\x0c\n\x04help\x18\x06 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x07 \x01(\t\x12\x12\n\x05value\x18\x08 \x01(\tH\x01\x88\x01\x01\x12\x11\n\tset_value\x18\t \x01(\x08\x12\x13\n\x0bplaceholder\x18\n \x01(\t\x12\x10\n\x08\x64isabled\x18\x0b \x01(\x08\x12\x31\n\x10label_visibility\x18\x0c \x01(\x0b\x32\x17.LabelVisibilityMessageB\n\n\x08_defaultB\x08\n\x06_valueb\x06proto3')
18
18
 
19
19
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
20
20
  _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'streamlit.proto.TextArea_pb2', globals())
@@ -22,5 +22,5 @@ if _descriptor._USE_C_DESCRIPTORS == False:
22
22
 
23
23
  DESCRIPTOR._options = None
24
24
  _TEXTAREA._serialized_start=81
25
- _TEXTAREA._serialized_end=325
25
+ _TEXTAREA._serialized_end=357
26
26
  # @@protoc_insertion_point(module_scope)
@@ -14,7 +14,7 @@ _sym_db = _symbol_database.Default()
14
14
  from streamlit.proto import LabelVisibilityMessage_pb2 as streamlit_dot_proto_dot_LabelVisibilityMessage__pb2
15
15
 
16
16
 
17
- DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1fstreamlit/proto/TextInput.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\xbd\x02\n\tTextInput\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x0f\n\x07\x64\x65\x66\x61ult\x18\x03 \x01(\t\x12\x1d\n\x04type\x18\x04 \x01(\x0e\x32\x0f.TextInput.Type\x12\x11\n\tmax_chars\x18\x05 \x01(\r\x12\x0c\n\x04help\x18\x06 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x07 \x01(\t\x12\r\n\x05value\x18\x08 \x01(\t\x12\x11\n\tset_value\x18\t \x01(\x08\x12\x14\n\x0c\x61utocomplete\x18\n \x01(\t\x12\x13\n\x0bplaceholder\x18\x0b \x01(\t\x12\x10\n\x08\x64isabled\x18\x0c \x01(\x08\x12\x31\n\x10label_visibility\x18\r \x01(\x0b\x32\x17.LabelVisibilityMessage\"!\n\x04Type\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x0c\n\x08PASSWORD\x10\x01\x62\x06proto3')
17
+ DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1fstreamlit/proto/TextInput.proto\x1a,streamlit/proto/LabelVisibilityMessage.proto\"\xdd\x02\n\tTextInput\x12\n\n\x02id\x18\x01 \x01(\t\x12\r\n\x05label\x18\x02 \x01(\t\x12\x14\n\x07\x64\x65\x66\x61ult\x18\x03 \x01(\tH\x00\x88\x01\x01\x12\x1d\n\x04type\x18\x04 \x01(\x0e\x32\x0f.TextInput.Type\x12\x11\n\tmax_chars\x18\x05 \x01(\r\x12\x0c\n\x04help\x18\x06 \x01(\t\x12\x0f\n\x07\x66orm_id\x18\x07 \x01(\t\x12\x12\n\x05value\x18\x08 \x01(\tH\x01\x88\x01\x01\x12\x11\n\tset_value\x18\t \x01(\x08\x12\x14\n\x0c\x61utocomplete\x18\n \x01(\t\x12\x13\n\x0bplaceholder\x18\x0b \x01(\t\x12\x10\n\x08\x64isabled\x18\x0c \x01(\x08\x12\x31\n\x10label_visibility\x18\r \x01(\x0b\x32\x17.LabelVisibilityMessage\"!\n\x04Type\x12\x0b\n\x07\x44\x45\x46\x41ULT\x10\x00\x12\x0c\n\x08PASSWORD\x10\x01\x42\n\n\x08_defaultB\x08\n\x06_valueb\x06proto3')
18
18
 
19
19
  _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals())
20
20
  _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'streamlit.proto.TextInput_pb2', globals())
@@ -22,7 +22,7 @@ if _descriptor._USE_C_DESCRIPTORS == False:
22
22
 
23
23
  DESCRIPTOR._options = None
24
24
  _TEXTINPUT._serialized_start=82
25
- _TEXTINPUT._serialized_end=399
26
- _TEXTINPUT_TYPE._serialized_start=366
27
- _TEXTINPUT_TYPE._serialized_end=399
25
+ _TEXTINPUT._serialized_end=431
26
+ _TEXTINPUT_TYPE._serialized_start=376
27
+ _TEXTINPUT_TYPE._serialized_end=409
28
28
  # @@protoc_insertion_point(module_scope)