streamlit-nightly 1.39.1.dev20241031__py2.py3-none-any.whl → 1.39.1.dev20241102__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.
- streamlit/commands/execution_control.py +7 -2
- streamlit/commands/logo.py +3 -3
- streamlit/commands/navigation.py +48 -3
- streamlit/commands/page_config.py +8 -3
- streamlit/elements/html.py +6 -4
- streamlit/elements/image.py +28 -443
- streamlit/elements/layouts.py +12 -7
- streamlit/elements/lib/image_utils.py +440 -0
- streamlit/elements/markdown.py +6 -0
- streamlit/elements/media.py +22 -9
- streamlit/elements/metric.py +8 -5
- streamlit/elements/progress.py +2 -1
- streamlit/elements/pyplot.py +3 -5
- streamlit/elements/text.py +1 -1
- streamlit/elements/widgets/audio_input.py +12 -11
- streamlit/elements/widgets/button.py +28 -19
- streamlit/elements/widgets/button_group.py +146 -121
- streamlit/elements/widgets/camera_input.py +13 -11
- streamlit/elements/widgets/chat.py +2 -2
- streamlit/elements/widgets/checkbox.py +30 -24
- streamlit/elements/widgets/color_picker.py +15 -13
- streamlit/elements/widgets/file_uploader.py +12 -12
- streamlit/elements/widgets/multiselect.py +33 -31
- streamlit/elements/widgets/number_input.py +15 -12
- streamlit/elements/widgets/radio.py +15 -12
- streamlit/elements/widgets/select_slider.py +15 -12
- streamlit/elements/widgets/selectbox.py +19 -14
- streamlit/elements/widgets/slider.py +15 -12
- streamlit/elements/widgets/text_widgets.py +33 -27
- streamlit/elements/widgets/time_widgets.py +33 -25
- streamlit/hello/{Animation_Demo.py → animation_demo.py} +9 -10
- streamlit/hello/{Dataframe_Demo.py → dataframe_demo.py} +9 -15
- streamlit/hello/{Hello.py → hello.py} +7 -12
- streamlit/hello/{Mapping_Demo.py → mapping_demo.py} +10 -13
- streamlit/hello/{Plotting_Demo.py → plotting_demo.py} +9 -10
- streamlit/hello/streamlit_app.py +24 -6
- streamlit/proto/Image_pb2.pyi +1 -1
- streamlit/static/asset-manifest.json +3 -3
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/3224.925d380f.chunk.js +1 -0
- streamlit/static/static/js/{main.754d974e.js → main.61a89bda.js} +2 -2
- {streamlit_nightly-1.39.1.dev20241031.dist-info → streamlit_nightly-1.39.1.dev20241102.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.39.1.dev20241031.dist-info → streamlit_nightly-1.39.1.dev20241102.dist-info}/RECORD +48 -47
- streamlit/static/static/js/3224.919d670d.chunk.js +0 -1
- /streamlit/static/static/js/{main.754d974e.js.LICENSE.txt → main.61a89bda.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.39.1.dev20241031.data → streamlit_nightly-1.39.1.dev20241102.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.39.1.dev20241031.dist-info → streamlit_nightly-1.39.1.dev20241102.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.39.1.dev20241031.dist-info → streamlit_nightly-1.39.1.dev20241102.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.39.1.dev20241031.dist-info → streamlit_nightly-1.39.1.dev20241102.dist-info}/top_level.txt +0 -0
@@ -17,6 +17,7 @@ from __future__ import annotations
|
|
17
17
|
import io
|
18
18
|
import os
|
19
19
|
from dataclasses import dataclass
|
20
|
+
from pathlib import Path
|
20
21
|
from textwrap import dedent
|
21
22
|
from typing import (
|
22
23
|
TYPE_CHECKING,
|
@@ -105,8 +106,9 @@ class ButtonMixin:
|
|
105
106
|
label : str
|
106
107
|
A short label explaining to the user what this button is for.
|
107
108
|
The label can optionally contain GitHub-flavored Markdown of the
|
108
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
109
|
-
|
109
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
110
|
+
and Images. Images display like icons, with a max height equal to
|
111
|
+
the font height.
|
110
112
|
|
111
113
|
Unsupported Markdown elements are unwrapped so only their children
|
112
114
|
(text contents) render. Display unsupported elements as literal
|
@@ -159,8 +161,8 @@ class ButtonMixin:
|
|
159
161
|
font library.
|
160
162
|
|
161
163
|
disabled : bool
|
162
|
-
An optional boolean
|
163
|
-
default is False
|
164
|
+
An optional boolean that disables the button if set to ``True``.
|
165
|
+
The default is ``False``.
|
164
166
|
|
165
167
|
use_container_width : bool
|
166
168
|
Whether to expand the button's width to fill its parent container.
|
@@ -270,8 +272,9 @@ class ButtonMixin:
|
|
270
272
|
label : str
|
271
273
|
A short label explaining to the user what this button is for.
|
272
274
|
The label can optionally contain GitHub-flavored Markdown of the
|
273
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
274
|
-
|
275
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
276
|
+
and Images. Images display like icons, with a max height equal to
|
277
|
+
the font height.
|
275
278
|
|
276
279
|
Unsupported Markdown elements are unwrapped so only their children
|
277
280
|
(text contents) render. Display unsupported elements as literal
|
@@ -340,8 +343,8 @@ class ButtonMixin:
|
|
340
343
|
font library.
|
341
344
|
|
342
345
|
disabled : bool
|
343
|
-
An optional boolean
|
344
|
-
True
|
346
|
+
An optional boolean that disables the download button if set to
|
347
|
+
``True``. The default is ``False``.
|
345
348
|
|
346
349
|
use_container_width : bool
|
347
350
|
Whether to expand the button's width to fill its parent container.
|
@@ -457,8 +460,9 @@ class ButtonMixin:
|
|
457
460
|
label : str
|
458
461
|
A short label explaining to the user what this button is for.
|
459
462
|
The label can optionally contain GitHub-flavored Markdown of the
|
460
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
461
|
-
|
463
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
464
|
+
and Images. Images display like icons, with a max height equal to
|
465
|
+
the font height.
|
462
466
|
|
463
467
|
Unsupported Markdown elements are unwrapped so only their children
|
464
468
|
(text contents) render. Display unsupported elements as literal
|
@@ -501,8 +505,8 @@ class ButtonMixin:
|
|
501
505
|
font library.
|
502
506
|
|
503
507
|
disabled : bool
|
504
|
-
An optional boolean
|
505
|
-
True
|
508
|
+
An optional boolean that disables the link button if set to
|
509
|
+
``True``. The default is ``False``.
|
506
510
|
|
507
511
|
use_container_width : bool
|
508
512
|
Whether to expand the button's width to fill its parent container.
|
@@ -544,7 +548,7 @@ class ButtonMixin:
|
|
544
548
|
@gather_metrics("page_link")
|
545
549
|
def page_link(
|
546
550
|
self,
|
547
|
-
page: str | StreamlitPage,
|
551
|
+
page: str | Path | StreamlitPage,
|
548
552
|
*,
|
549
553
|
label: str | None = None,
|
550
554
|
icon: str | None = None,
|
@@ -564,7 +568,7 @@ class ButtonMixin:
|
|
564
568
|
|
565
569
|
Parameters
|
566
570
|
----------
|
567
|
-
page : str or st.Page
|
571
|
+
page : str, Path, or st.Page
|
568
572
|
The file path (relative to the main script) or an st.Page indicating
|
569
573
|
the page to switch to. Alternatively, this can be the URL to an
|
570
574
|
external page (must start with "http://" or "https://").
|
@@ -572,8 +576,9 @@ class ButtonMixin:
|
|
572
576
|
label : str
|
573
577
|
The label for the page link. Labels are required for external pages.
|
574
578
|
The label can optionally contain GitHub-flavored Markdown of the
|
575
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
576
|
-
|
579
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
580
|
+
and Images. Images display like icons, with a max height equal to
|
581
|
+
the font height.
|
577
582
|
|
578
583
|
Unsupported Markdown elements are unwrapped so only their children
|
579
584
|
(text contents) render. Display unsupported elements as literal
|
@@ -608,8 +613,8 @@ class ButtonMixin:
|
|
608
613
|
hovered over.
|
609
614
|
|
610
615
|
disabled : bool
|
611
|
-
An optional boolean
|
612
|
-
|
616
|
+
An optional boolean that disables the page link if set to ``True``.
|
617
|
+
The default is ``False``.
|
613
618
|
|
614
619
|
use_container_width : bool
|
615
620
|
Whether to expand the link's width to fill its parent container.
|
@@ -764,7 +769,7 @@ class ButtonMixin:
|
|
764
769
|
|
765
770
|
def _page_link(
|
766
771
|
self,
|
767
|
-
page: str | StreamlitPage,
|
772
|
+
page: str | Path | StreamlitPage,
|
768
773
|
*, # keyword-only arguments:
|
769
774
|
label: str | None = None,
|
770
775
|
icon: str | None = None,
|
@@ -793,6 +798,10 @@ class ButtonMixin:
|
|
793
798
|
if label is None:
|
794
799
|
page_link_proto.label = page.title
|
795
800
|
else:
|
801
|
+
# Convert Path to string if necessary
|
802
|
+
if isinstance(page, Path):
|
803
|
+
page = str(page)
|
804
|
+
|
796
805
|
# Handle external links:
|
797
806
|
if is_url(page):
|
798
807
|
if label is None or label == "":
|
@@ -300,9 +300,8 @@ class ButtonGroupMixin:
|
|
300
300
|
based on its content. No two widgets may have the same key.
|
301
301
|
|
302
302
|
disabled : bool
|
303
|
-
An optional boolean
|
304
|
-
to True
|
305
|
-
by keyword.
|
303
|
+
An optional boolean that disables the feedback widget if set
|
304
|
+
to ``True``. The default is ``False``.
|
306
305
|
|
307
306
|
on_change : callable
|
308
307
|
An optional callback invoked when this feedback widget's value
|
@@ -440,16 +439,18 @@ class ButtonGroupMixin:
|
|
440
439
|
) -> list[V] | V | None:
|
441
440
|
r"""Display a pills widget.
|
442
441
|
|
443
|
-
A pills widget is similar to a
|
444
|
-
``options`` are
|
442
|
+
A pills widget is similar to a ``st.selectbox`` or ``st.multiselect``
|
443
|
+
where the ``options`` are displayed as pill-buttons instead of a
|
444
|
+
drop-down list.
|
445
445
|
|
446
446
|
Parameters
|
447
447
|
----------
|
448
|
-
label
|
448
|
+
label: str
|
449
449
|
A short label explaining to the user what this widget is for.
|
450
450
|
The label can optionally contain GitHub-flavored Markdown of the
|
451
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
452
|
-
|
451
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
452
|
+
and Images. Images display like icons, with a max height equal to
|
453
|
+
the font height.
|
453
454
|
|
454
455
|
Unsupported Markdown elements are unwrapped so only their children
|
455
456
|
(text contents) render. Display unsupported elements as literal
|
@@ -459,106 +460,116 @@ class ButtonGroupMixin:
|
|
459
460
|
See the ``body`` parameter of |st.markdown|_ for additional,
|
460
461
|
supported Markdown directives.
|
461
462
|
|
462
|
-
For accessibility reasons, you should never set an empty label
|
463
|
-
|
464
|
-
empty labels by raising an exception.
|
463
|
+
For accessibility reasons, you should never set an empty label, but
|
464
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
465
|
+
we may disallow empty labels by raising an exception.
|
465
466
|
|
466
467
|
.. |st.markdown| replace:: ``st.markdown``
|
467
468
|
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
468
469
|
|
469
|
-
selection_mode: "single" or "multi"
|
470
|
-
The selection mode for the widget. If "single", only one option can be
|
471
|
-
selected. If "multi", multiple options can be selected.
|
472
|
-
|
473
470
|
options: Iterable of V
|
474
471
|
Labels for the select options in an ``Iterable``. This can be a
|
475
472
|
``list``, ``set``, or anything supported by ``st.dataframe``. If
|
476
473
|
``options`` is dataframe-like, the first column will be used. Each
|
477
474
|
label will be cast to ``str`` internally by default.
|
478
475
|
|
476
|
+
selection_mode: "single" or "multi"
|
477
|
+
The selection mode for the widget. If this is ``"single"``
|
478
|
+
(default), only one option can be selected. If this is ``"multi"``,
|
479
|
+
multiple options can be selected.
|
480
|
+
|
479
481
|
default: Iterable of V, V, or None
|
480
|
-
|
481
|
-
is
|
482
|
+
The value of the widget when it first renders. If the
|
483
|
+
``selection_mode`` is ``multi``, this can be a list of values, a
|
484
|
+
single value, or ``None``. If the ``selection_mode`` is
|
485
|
+
``"single"``, this can be a single value or ``None``.
|
482
486
|
|
483
|
-
format_func
|
487
|
+
format_func: function
|
484
488
|
Function to modify the display of the options. It receives
|
485
489
|
the raw option as an argument and should output the label to be
|
486
490
|
shown for that option. This has no impact on the return value of
|
487
491
|
the command.
|
488
492
|
|
489
|
-
key
|
493
|
+
key: str or int
|
490
494
|
An optional string or integer to use as the unique key for the widget.
|
491
495
|
If this is omitted, a key will be generated for the widget
|
492
496
|
based on its content. Multiple widgets of the same type may
|
493
497
|
not share the same key.
|
494
498
|
|
495
|
-
help
|
496
|
-
An optional tooltip that gets displayed next to the
|
499
|
+
help: str
|
500
|
+
An optional tooltip that gets displayed next to the widget label.
|
501
|
+
Streamlit only displays the tooltip when
|
502
|
+
``label_visibility="visible"``.
|
497
503
|
|
498
|
-
on_change
|
499
|
-
An optional callback invoked when this
|
500
|
-
changes.
|
504
|
+
on_change: callable
|
505
|
+
An optional callback invoked when this widget's value changes.
|
501
506
|
|
502
|
-
args
|
507
|
+
args: tuple
|
503
508
|
An optional tuple of args to pass to the callback.
|
504
509
|
|
505
|
-
kwargs
|
510
|
+
kwargs: dict
|
506
511
|
An optional dict of kwargs to pass to the callback.
|
507
512
|
|
508
|
-
disabled
|
509
|
-
An optional boolean
|
510
|
-
|
511
|
-
by keyword.
|
513
|
+
disabled: bool
|
514
|
+
An optional boolean that disables the widget if set to ``True``.
|
515
|
+
The default is ``False``.
|
512
516
|
|
513
|
-
label_visibility
|
514
|
-
The visibility of the label.
|
515
|
-
is
|
516
|
-
|
517
|
-
"
|
517
|
+
label_visibility: "visible", "hidden", or "collapsed"
|
518
|
+
The visibility of the label. The default is ``"visible"``. If this
|
519
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
520
|
+
label, which can help keep the widget alligned with other widgets.
|
521
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
518
522
|
|
519
523
|
Returns
|
520
524
|
-------
|
521
|
-
list of V
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
or None.
|
525
|
+
list of V, V, or None
|
526
|
+
If the ``selection_mode`` is ``multi``, this is a list of selected
|
527
|
+
options or an empty list. If the ``selection_mode`` is
|
528
|
+
``"single"``, this is a selected option or ``None``.
|
526
529
|
|
527
530
|
Examples
|
528
531
|
--------
|
529
|
-
|
532
|
+
|
533
|
+
**Example 1: Multi-select pills**
|
534
|
+
|
535
|
+
Display a multi-select pills widget, and show the selection:
|
530
536
|
|
531
537
|
>>> import streamlit as st
|
532
538
|
>>>
|
533
|
-
>>> options = ["
|
534
|
-
>>> selection = st.pills(
|
535
|
-
|
536
|
-
>>> st.markdown(f"You selected option: '{selection}'.")
|
539
|
+
>>> options = ["North", "East", "South", "West"]
|
540
|
+
>>> selection = st.pills("Directions", options, selection_mode="multi")
|
541
|
+
>>> st.markdown(f"Your selected options: {selection}.")
|
537
542
|
|
538
|
-
.. output
|
539
|
-
|
543
|
+
.. output::
|
544
|
+
https://doc-pills-multi.streamlit.app/
|
545
|
+
height: 200px
|
540
546
|
|
547
|
+
**Example 2: Single-select pills with icons**
|
541
548
|
|
542
|
-
Display a pills widget
|
549
|
+
Display a single-select pills widget with icons:
|
543
550
|
|
544
551
|
>>> import streamlit as st
|
545
552
|
>>>
|
546
|
-
>>>
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
553
|
+
>>> option_map = {
|
554
|
+
... 0: ":material/add:",
|
555
|
+
... 1: ":material/zoom_in:",
|
556
|
+
... 2: ":material/zoom_out:",
|
557
|
+
... 3: ":material/zoom_out_map:",
|
558
|
+
... }
|
552
559
|
>>> selection = st.pills(
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
>>> st.write(
|
559
|
-
|
560
|
-
|
561
|
-
|
560
|
+
... "Tool",
|
561
|
+
... options=option_map.keys(),
|
562
|
+
... format_func=lambda option: option_map[option],
|
563
|
+
... selection_mode="single",
|
564
|
+
... )
|
565
|
+
>>> st.write(
|
566
|
+
... "Your selected option: "
|
567
|
+
... f"{None if selection is None else option_map[selection]}"
|
568
|
+
... )
|
569
|
+
|
570
|
+
.. output::
|
571
|
+
https://doc-pills-single.streamlit.app/
|
572
|
+
height: 200px
|
562
573
|
|
563
574
|
"""
|
564
575
|
return self._internal_button_group(
|
@@ -631,16 +642,17 @@ class ButtonGroupMixin:
|
|
631
642
|
) -> list[V] | V | None:
|
632
643
|
r"""Display a segmented control widget.
|
633
644
|
|
634
|
-
A segmented control widget is a linear set of segments where each of
|
635
|
-
``options`` functions
|
645
|
+
A segmented control widget is a linear set of segments where each of
|
646
|
+
the passed ``options`` functions like a toggle button.
|
636
647
|
|
637
648
|
Parameters
|
638
649
|
----------
|
639
650
|
label : str
|
640
651
|
A short label explaining to the user what this widget is for.
|
641
652
|
The label can optionally contain GitHub-flavored Markdown of the
|
642
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
643
|
-
|
653
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
654
|
+
and Images. Images display like icons, with a max height equal to
|
655
|
+
the font height.
|
644
656
|
|
645
657
|
Unsupported Markdown elements are unwrapped so only their children
|
646
658
|
(text contents) render. Display unsupported elements as literal
|
@@ -650,106 +662,119 @@ class ButtonGroupMixin:
|
|
650
662
|
See the ``body`` parameter of |st.markdown|_ for additional,
|
651
663
|
supported Markdown directives.
|
652
664
|
|
653
|
-
For accessibility reasons, you should never set an empty label
|
654
|
-
|
655
|
-
empty labels by raising an exception.
|
665
|
+
For accessibility reasons, you should never set an empty label, but
|
666
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
667
|
+
we may disallow empty labels by raising an exception.
|
656
668
|
|
657
669
|
.. |st.markdown| replace:: ``st.markdown``
|
658
670
|
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
659
671
|
|
660
|
-
selection_mode: "single" or "multi"
|
661
|
-
The selection mode for the widget. If "single", only one option can be
|
662
|
-
selected. If "multi", multiple options can be selected.
|
663
|
-
|
664
672
|
options: Iterable of V
|
665
673
|
Labels for the select options in an ``Iterable``. This can be a
|
666
674
|
``list``, ``set``, or anything supported by ``st.dataframe``. If
|
667
675
|
``options`` is dataframe-like, the first column will be used. Each
|
668
676
|
label will be cast to ``str`` internally by default.
|
669
677
|
|
678
|
+
selection_mode: "single" or "multi"
|
679
|
+
The selection mode for the widget. If this is ``"single"``
|
680
|
+
(default), only one option can be selected. If this is ``"multi"``,
|
681
|
+
multiple options can be selected.
|
682
|
+
|
670
683
|
default: Iterable of V, V, or None
|
671
|
-
|
672
|
-
is
|
684
|
+
The value of the widget when it first renders. If the
|
685
|
+
``selection_mode`` is ``multi``, this can be a list of values, a
|
686
|
+
single value, or ``None``. If the ``selection_mode`` is
|
687
|
+
``"single"``, this can be a single value or ``None``.
|
673
688
|
|
674
|
-
format_func
|
689
|
+
format_func: function
|
675
690
|
Function to modify the display of the options. It receives
|
676
691
|
the raw option as an argument and should output the label to be
|
677
692
|
shown for that option. This has no impact on the return value of
|
678
693
|
the command.
|
679
694
|
|
680
|
-
key
|
695
|
+
key: str or int
|
681
696
|
An optional string or integer to use as the unique key for the widget.
|
682
697
|
If this is omitted, a key will be generated for the widget
|
683
698
|
based on its content. Multiple widgets of the same type may
|
684
699
|
not share the same key.
|
685
700
|
|
686
|
-
help
|
687
|
-
An optional tooltip that gets displayed next to the
|
701
|
+
help: str
|
702
|
+
An optional tooltip that gets displayed next to the widget label.
|
703
|
+
Streamlit only displays the tooltip when
|
704
|
+
``label_visibility="visible"``.
|
688
705
|
|
689
|
-
on_change
|
690
|
-
An optional callback invoked when this
|
691
|
-
changes.
|
706
|
+
on_change: callable
|
707
|
+
An optional callback invoked when this widget's value changes.
|
692
708
|
|
693
|
-
args
|
709
|
+
args: tuple
|
694
710
|
An optional tuple of args to pass to the callback.
|
695
711
|
|
696
|
-
kwargs
|
712
|
+
kwargs: dict
|
697
713
|
An optional dict of kwargs to pass to the callback.
|
698
714
|
|
699
|
-
disabled
|
700
|
-
An optional boolean
|
701
|
-
|
702
|
-
by keyword.
|
715
|
+
disabled: bool
|
716
|
+
An optional boolean that disables the widget if set to ``True``.
|
717
|
+
The default is ``False``.
|
703
718
|
|
704
|
-
label_visibility
|
705
|
-
The visibility of the label.
|
706
|
-
is
|
707
|
-
|
708
|
-
"
|
719
|
+
label_visibility: "visible", "hidden", or "collapsed"
|
720
|
+
The visibility of the label. The default is ``"visible"``. If this
|
721
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
722
|
+
label, which can help keep the widget alligned with other widgets.
|
723
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
709
724
|
|
710
725
|
Returns
|
711
726
|
-------
|
712
|
-
list of V
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
or None.
|
727
|
+
list of V, V, or None
|
728
|
+
If the ``selection_mode`` is ``multi``, this is a list of selected
|
729
|
+
options or an empty list. If the ``selection_mode`` is
|
730
|
+
``"single"``, this is a selected option or ``None``.
|
717
731
|
|
718
732
|
Examples
|
719
733
|
--------
|
720
|
-
|
734
|
+
|
735
|
+
**Example 1: Multi-select segmented control**
|
736
|
+
|
737
|
+
Display a multi-select segmented control widget, and show the
|
738
|
+
selection:
|
721
739
|
|
722
740
|
>>> import streamlit as st
|
723
741
|
>>>
|
724
742
|
>>> options = ["North", "East", "South", "West"]
|
725
|
-
>>> selection = st.segmented_control(
|
726
|
-
|
727
|
-
|
743
|
+
>>> selection = st.segmented_control(
|
744
|
+
... "Directions", options, selection_mode="multi"
|
745
|
+
... )
|
746
|
+
>>> st.markdown(f"Your selected options: {selection}.")
|
728
747
|
|
729
|
-
.. output
|
730
|
-
|
748
|
+
.. output::
|
749
|
+
https://doc-segmented-control-multi.streamlit.app/
|
750
|
+
height: 200px
|
731
751
|
|
752
|
+
**Example 2: Single-select segmented control with icons**
|
732
753
|
|
733
|
-
Display a segmented control widget
|
754
|
+
Display a single-select segmented control widget with icons:
|
734
755
|
|
735
756
|
>>> import streamlit as st
|
736
757
|
>>>
|
737
|
-
>>>
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
758
|
+
>>> option_map = {
|
759
|
+
... 0: ":material/add:",
|
760
|
+
... 1: ":material/zoom_in:",
|
761
|
+
... 2: ":material/zoom_out:",
|
762
|
+
... 3: ":material/zoom_out_map:",
|
763
|
+
... }
|
743
764
|
>>> selection = st.segmented_control(
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
>>> st.write(
|
750
|
-
|
751
|
-
|
752
|
-
|
765
|
+
... "Tool",
|
766
|
+
... options=option_map.keys(),
|
767
|
+
... format_func=lambda option: option_map[option],
|
768
|
+
... selection_mode="single",
|
769
|
+
... )
|
770
|
+
>>> st.write(
|
771
|
+
... "Your selected option: "
|
772
|
+
... f"{None if selection is None else option_map[selection]}"
|
773
|
+
... )
|
774
|
+
|
775
|
+
.. output::
|
776
|
+
https://doc-segmented-control-single.streamlit.app/
|
777
|
+
height: 200px
|
753
778
|
|
754
779
|
"""
|
755
780
|
return self._internal_button_group(
|
@@ -103,8 +103,9 @@ class CameraInputMixin:
|
|
103
103
|
label : str
|
104
104
|
A short label explaining to the user what this widget is used for.
|
105
105
|
The label can optionally contain GitHub-flavored Markdown of the
|
106
|
-
following types: Bold, Italics, Strikethroughs, Inline Code,
|
107
|
-
|
106
|
+
following types: Bold, Italics, Strikethroughs, Inline Code, Links,
|
107
|
+
and Images. Images display like icons, with a max height equal to
|
108
|
+
the font height.
|
108
109
|
|
109
110
|
Unsupported Markdown elements are unwrapped so only their children
|
110
111
|
(text contents) render. Display unsupported elements as literal
|
@@ -114,9 +115,9 @@ class CameraInputMixin:
|
|
114
115
|
See the ``body`` parameter of |st.markdown|_ for additional,
|
115
116
|
supported Markdown directives.
|
116
117
|
|
117
|
-
For accessibility reasons, you should never set an empty label
|
118
|
-
|
119
|
-
empty labels by raising an exception.
|
118
|
+
For accessibility reasons, you should never set an empty label, but
|
119
|
+
you can hide it with ``label_visibility`` if needed. In the future,
|
120
|
+
we may disallow empty labels by raising an exception.
|
120
121
|
|
121
122
|
.. |st.markdown| replace:: ``st.markdown``
|
122
123
|
.. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
|
@@ -140,13 +141,14 @@ class CameraInputMixin:
|
|
140
141
|
An optional dict of kwargs to pass to the callback.
|
141
142
|
|
142
143
|
disabled : bool
|
143
|
-
An optional boolean
|
144
|
-
True
|
144
|
+
An optional boolean that disables the camera input if set to
|
145
|
+
``True``. Default is ``False``.
|
146
|
+
|
145
147
|
label_visibility : "visible", "hidden", or "collapsed"
|
146
|
-
The visibility of the label.
|
147
|
-
is
|
148
|
-
|
149
|
-
"
|
148
|
+
The visibility of the label. The default is ``"visible"``. If this
|
149
|
+
is ``"hidden"``, Streamlit displays an empty spacer instead of the
|
150
|
+
label, which can help keep the widget alligned with other widgets.
|
151
|
+
If this is ``"collapsed"``, Streamlit displays no label or spacer.
|
150
152
|
|
151
153
|
Returns
|
152
154
|
-------
|
@@ -20,8 +20,8 @@ from typing import TYPE_CHECKING, Literal, cast
|
|
20
20
|
|
21
21
|
from streamlit import runtime
|
22
22
|
from streamlit.delta_generator_singletons import get_dg_singleton_instance
|
23
|
-
from streamlit.elements.image import AtomicImage, WidthBehaviour, image_to_url
|
24
23
|
from streamlit.elements.lib.form_utils import is_in_form
|
24
|
+
from streamlit.elements.lib.image_utils import AtomicImage, WidthBehavior, image_to_url
|
25
25
|
from streamlit.elements.lib.policies import check_widget_policies
|
26
26
|
from streamlit.elements.lib.utils import (
|
27
27
|
Key,
|
@@ -96,7 +96,7 @@ def _process_avatar_input(
|
|
96
96
|
try:
|
97
97
|
return AvatarType.IMAGE, image_to_url(
|
98
98
|
avatar,
|
99
|
-
width=
|
99
|
+
width=WidthBehavior.ORIGINAL,
|
100
100
|
clamp=False,
|
101
101
|
channels="RGB",
|
102
102
|
output_format="auto",
|