streamlit-nightly 1.36.1.dev20240626__py2.py3-none-any.whl → 1.36.1.dev20240628__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 (29) hide show
  1. streamlit/commands/page_config.py +2 -2
  2. streamlit/components/v1/components.py +1 -1
  3. streamlit/elements/alert.py +2 -2
  4. streamlit/elements/graphviz_chart.py +4 -2
  5. streamlit/elements/layouts.py +2 -2
  6. streamlit/elements/lib/built_in_chart_utils.py +104 -19
  7. streamlit/elements/toast.py +2 -2
  8. streamlit/elements/vega_charts.py +25 -1
  9. streamlit/elements/widgets/button.py +2 -2
  10. streamlit/elements/widgets/chat.py +2 -2
  11. streamlit/material_icon_names.py +9 -4
  12. streamlit/navigation/page.py +3 -3
  13. streamlit/static/asset-manifest.json +5 -5
  14. streamlit/static/index.html +1 -1
  15. streamlit/static/static/css/{main.3aaaea00.css → main.29bca1b5.css} +1 -1
  16. streamlit/static/static/js/main.0326e951.js +2 -0
  17. streamlit/static/static/media/MaterialSymbols-Rounded.ec07649f7a20048d5730.woff2 +0 -0
  18. streamlit/testing/v1/element_tree.py +11 -11
  19. streamlit/type_util.py +3 -0
  20. streamlit/web/server/routes.py +6 -1
  21. {streamlit_nightly-1.36.1.dev20240626.dist-info → streamlit_nightly-1.36.1.dev20240628.dist-info}/METADATA +1 -1
  22. {streamlit_nightly-1.36.1.dev20240626.dist-info → streamlit_nightly-1.36.1.dev20240628.dist-info}/RECORD +27 -27
  23. streamlit/static/static/js/main.5b854b9d.js +0 -2
  24. streamlit/static/static/media/MaterialSymbols-Outlined.909d2dce4aba724ad02f.woff2 +0 -0
  25. /streamlit/static/static/js/{main.5b854b9d.js.LICENSE.txt → main.0326e951.js.LICENSE.txt} +0 -0
  26. {streamlit_nightly-1.36.1.dev20240626.data → streamlit_nightly-1.36.1.dev20240628.data}/scripts/streamlit.cmd +0 -0
  27. {streamlit_nightly-1.36.1.dev20240626.dist-info → streamlit_nightly-1.36.1.dev20240628.dist-info}/WHEEL +0 -0
  28. {streamlit_nightly-1.36.1.dev20240626.dist-info → streamlit_nightly-1.36.1.dev20240628.dist-info}/entry_points.txt +0 -0
  29. {streamlit_nightly-1.36.1.dev20240626.dist-info → streamlit_nightly-1.36.1.dev20240628.dist-info}/top_level.txt +0 -0
@@ -154,13 +154,13 @@ def set_page_config(
154
154
  to set a random emoji from the supported list above. Emoji icons are
155
155
  courtesy of Twemoji and loaded from MaxCDN.
156
156
 
157
- * An icon from the Material Symbols library (outlined style) in the
157
+ * An icon from the Material Symbols library (rounded style) in the
158
158
  format ``":material/icon_name:"`` where "icon_name" is the name
159
159
  of the icon in snake case.
160
160
 
161
161
  For example, ``icon=":material/thumb_up:"`` will display the
162
162
  Thumb Up icon. Find additional icons in the `Material Symbols \
163
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
163
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
164
164
  font library.
165
165
 
166
166
  .. note::
@@ -20,6 +20,6 @@
20
20
  # model the old behavior and not to break things.
21
21
 
22
22
  from streamlit.components.v1.component_registry import (
23
- declare_component as declare_component,
23
+ declare_component as declare_component, # noqa: PLC0414
24
24
  )
25
25
  from streamlit.components.v1.custom_component import * # noqa: F403
@@ -53,7 +53,7 @@ class AlertMixin:
53
53
 
54
54
  For example, ``icon=":material/thumb_up:"`` will display the
55
55
  Thumb Up icon. Find additional icons in the `Material Symbols \
56
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
56
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
57
57
  font library.
58
58
 
59
59
  Example
@@ -91,7 +91,7 @@ class AlertMixin:
91
91
  * A single-character emoji. For example, you can set ``icon="🚨"``
92
92
  or ``icon="🔥"``. Emoji short codes are not supported.
93
93
 
94
- * An icon from the Material Symbols library (outlined style) in the
94
+ * An icon from the Material Symbols library (rounded style) in the
95
95
  format ``":material/icon_name:"`` where "icon_name" is the name
96
96
  of the icon in snake case.
97
97
 
@@ -32,7 +32,9 @@ if TYPE_CHECKING:
32
32
 
33
33
  from streamlit.delta_generator import DeltaGenerator
34
34
 
35
- FigureOrDot: TypeAlias = Union["graphviz.Graph", "graphviz.Digraph", str]
35
+ FigureOrDot: TypeAlias = Union[
36
+ "graphviz.Graph", "graphviz.Digraph", "graphviz.Source", str
37
+ ]
36
38
 
37
39
 
38
40
  class GraphvizMixin:
@@ -46,7 +48,7 @@ class GraphvizMixin:
46
48
 
47
49
  Parameters
48
50
  ----------
49
- figure_or_dot : graphviz.dot.Graph, graphviz.dot.Digraph, str
51
+ figure_or_dot : graphviz.dot.Graph, graphviz.dot.Digraph, graphviz.sources.Source, str
50
52
  The Graphlib graph object or dot string to display
51
53
 
52
54
  use_container_width : bool
@@ -503,13 +503,13 @@ class LayoutsMixin:
503
503
  * A single-character emoji. For example, you can set ``icon="🚨"``
504
504
  or ``icon="🔥"``. Emoji short codes are not supported.
505
505
 
506
- * An icon from the Material Symbols library (outlined style) in the
506
+ * An icon from the Material Symbols library (rounded style) in the
507
507
  format ``":material/icon_name:"`` where "icon_name" is the name
508
508
  of the icon in snake case.
509
509
 
510
510
  For example, ``icon=":material/thumb_up:"`` will display the
511
511
  Thumb Up icon. Find additional icons in the `Material Symbols \
512
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
512
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
513
513
  font library.
514
514
 
515
515
  Examples
@@ -45,7 +45,7 @@ if TYPE_CHECKING:
45
45
  import pandas as pd
46
46
 
47
47
  from streamlit.elements.arrow import Data
48
- from streamlit.type_util import DataFrameCompatible
48
+ from streamlit.type_util import ChartStackType, DataFrameCompatible
49
49
 
50
50
 
51
51
  class PrepDataColumns(TypedDict):
@@ -123,6 +123,8 @@ def generate_chart(
123
123
  size_from_user: str | float | None = None,
124
124
  width: int | None = None,
125
125
  height: int | None = None,
126
+ # Bar charts only:
127
+ stack: bool | ChartStackType | None = None,
126
128
  ) -> tuple[alt.Chart, AddRowsMetadata]:
127
129
  """Function to use the chart's type, data columns and indices to figure out the chart's spec."""
128
130
  import altair as alt
@@ -166,21 +168,18 @@ def generate_chart(
166
168
 
167
169
  # At this point, x_column is only None if user did not provide one AND df is empty.
168
170
 
169
- if chart_type == ChartType.HORIZONTAL_BAR:
170
- # Handle horizontal bar chart - switches x and y data:
171
- x_encoding = _get_x_encoding(
172
- df, y_column, y_from_user, x_axis_label, chart_type
173
- )
174
- y_encoding = _get_y_encoding(
175
- df, x_column, x_from_user, y_axis_label, chart_type
176
- )
177
- else:
178
- x_encoding = _get_x_encoding(
179
- df, x_column, x_from_user, x_axis_label, chart_type
180
- )
181
- y_encoding = _get_y_encoding(
182
- df, y_column, y_from_user, y_axis_label, chart_type
183
- )
171
+ # Get x and y encodings
172
+ x_encoding, y_encoding = _get_axis_encodings(
173
+ df,
174
+ chart_type,
175
+ x_column,
176
+ y_column,
177
+ x_from_user,
178
+ y_from_user,
179
+ x_axis_label,
180
+ y_axis_label,
181
+ stack,
182
+ )
184
183
 
185
184
  # Create a Chart with x and y encodings.
186
185
  chart = alt.Chart(
@@ -193,8 +192,21 @@ def generate_chart(
193
192
  y=y_encoding,
194
193
  )
195
194
 
195
+ # Offset encoding only works for Altair >= 5.0.0
196
+ is_altair_version_offset_compatible = not type_util.is_altair_version_less_than(
197
+ "5.0.0"
198
+ )
199
+ # Set up offset encoding (creates grouped/non-stacked bar charts, so only applicable when stack=False).
200
+ if (
201
+ is_altair_version_offset_compatible
202
+ and stack is False
203
+ and color_column is not None
204
+ ):
205
+ x_offset, y_offset = _get_offset_encoding(chart_type, color_column)
206
+ chart = chart.encode(xOffset=x_offset, yOffset=y_offset)
207
+
196
208
  # Set up opacity encoding.
197
- opacity_enc = _get_opacity_encoding(chart_type, color_column)
209
+ opacity_enc = _get_opacity_encoding(chart_type, stack, color_column)
198
210
  if opacity_enc is not None:
199
211
  chart = chart.encode(opacity=opacity_enc)
200
212
 
@@ -484,7 +496,7 @@ def _maybe_convert_color_column_in_place(df: pd.DataFrame, color_column: str | N
484
496
  pass
485
497
  elif is_color_tuple_like(first_color_datum):
486
498
  # Tuples need to be converted to CSS-valid.
487
- df[color_column] = df[color_column].map(to_css_color)
499
+ df.loc[:, color_column] = df[color_column].map(to_css_color)
488
500
  else:
489
501
  # Other kinds of colors columns (i.e. pure numbers or nominal strings) shouldn't
490
502
  # be converted since they are treated by Vega-Lite as sequential or categorical colors.
@@ -577,14 +589,38 @@ def _parse_y_columns(
577
589
  return y_column_list
578
590
 
579
591
 
592
+ def _get_offset_encoding(
593
+ chart_type: ChartType,
594
+ color_column: str | None,
595
+ ) -> tuple[alt.XOffset, alt.YOffset]:
596
+ # Vega's Offset encoding channel is used to create grouped/non-stacked bar charts
597
+ import altair as alt
598
+
599
+ x_offset = alt.XOffset()
600
+ y_offset = alt.YOffset()
601
+
602
+ if chart_type is ChartType.VERTICAL_BAR:
603
+ x_offset = alt.XOffset(field=color_column)
604
+ elif chart_type is ChartType.HORIZONTAL_BAR:
605
+ y_offset = alt.YOffset(field=color_column)
606
+
607
+ return x_offset, y_offset
608
+
609
+
580
610
  def _get_opacity_encoding(
581
- chart_type: ChartType, color_column: str | None
611
+ chart_type: ChartType,
612
+ stack: bool | ChartStackType | None,
613
+ color_column: str | None,
582
614
  ) -> alt.OpacityValue | None:
583
615
  import altair as alt
584
616
 
585
617
  if color_column and chart_type == ChartType.AREA:
586
618
  return alt.OpacityValue(0.7)
587
619
 
620
+ # Layered bar chart
621
+ if color_column and stack == "layered":
622
+ return alt.OpacityValue(0.7)
623
+
588
624
  return None
589
625
 
590
626
 
@@ -634,6 +670,42 @@ def _maybe_melt(
634
670
  return df, y_column, color_column
635
671
 
636
672
 
673
+ def _get_axis_encodings(
674
+ df: pd.DataFrame,
675
+ chart_type: ChartType,
676
+ x_column: str | None,
677
+ y_column: str | None,
678
+ x_from_user: str | None,
679
+ y_from_user: str | Sequence[str] | None,
680
+ x_axis_label: str | None,
681
+ y_axis_label: str | None,
682
+ stack: bool | ChartStackType | None,
683
+ ) -> tuple[alt.X, alt.Y]:
684
+ stack_encoding: alt.X | alt.Y
685
+ if chart_type == ChartType.HORIZONTAL_BAR:
686
+ # Handle horizontal bar chart - switches x and y data:
687
+ x_encoding = _get_x_encoding(
688
+ df, y_column, y_from_user, x_axis_label, chart_type
689
+ )
690
+ y_encoding = _get_y_encoding(
691
+ df, x_column, x_from_user, y_axis_label, chart_type
692
+ )
693
+ stack_encoding = x_encoding
694
+ else:
695
+ x_encoding = _get_x_encoding(
696
+ df, x_column, x_from_user, x_axis_label, chart_type
697
+ )
698
+ y_encoding = _get_y_encoding(
699
+ df, y_column, y_from_user, y_axis_label, chart_type
700
+ )
701
+ stack_encoding = y_encoding
702
+
703
+ # Handle stacking - only relevant for bar charts
704
+ _update_encoding_with_stack(stack, stack_encoding)
705
+
706
+ return x_encoding, y_encoding
707
+
708
+
637
709
  def _get_x_encoding(
638
710
  df: pd.DataFrame,
639
711
  x_column: str | None,
@@ -730,6 +802,19 @@ def _get_y_encoding(
730
802
  )
731
803
 
732
804
 
805
+ def _update_encoding_with_stack(
806
+ stack: bool | ChartStackType | None,
807
+ encoding: alt.X | alt.Y,
808
+ ) -> None:
809
+ if stack is None:
810
+ return None
811
+ # Our layered option maps to vega's stack=False option
812
+ elif stack == "layered":
813
+ stack = False
814
+
815
+ encoding["stack"] = stack
816
+
817
+
733
818
  def _get_color_encoding(
734
819
  df: pd.DataFrame,
735
820
  color_value: Color | None,
@@ -82,13 +82,13 @@ class ToastMixin:
82
82
  * A single-character emoji. For example, you can set ``icon="🚨"``
83
83
  or ``icon="🔥"``. Emoji short codes are not supported.
84
84
 
85
- * An icon from the Material Symbols library (outlined style) in the
85
+ * An icon from the Material Symbols library (rounded style) in the
86
86
  format ``":material/icon_name:"`` where "icon_name" is the name
87
87
  of the icon in snake case.
88
88
 
89
89
  For example, ``icon=":material/thumb_up:"`` will display the
90
90
  Thumb Up icon. Find additional icons in the `Material Symbols \
91
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
91
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
92
92
  font library.
93
93
 
94
94
  Example
@@ -57,7 +57,7 @@ from streamlit.runtime.metrics_util import gather_metrics
57
57
  from streamlit.runtime.scriptrunner import get_script_run_ctx
58
58
  from streamlit.runtime.state import register_widget
59
59
  from streamlit.runtime.state.common import compute_widget_id
60
- from streamlit.type_util import Key, to_key
60
+ from streamlit.type_util import ChartStackType, Key, to_key
61
61
  from streamlit.util import HASHLIB_KWARGS
62
62
 
63
63
  if TYPE_CHECKING:
@@ -957,6 +957,7 @@ class VegaChartsMixin:
957
957
  y_label: str | None = None,
958
958
  color: str | Color | list[Color] | None = None,
959
959
  horizontal: bool = False,
960
+ stack: bool | ChartStackType | None = None,
960
961
  width: int | None = None,
961
962
  height: int | None = None,
962
963
  use_container_width: bool = True,
@@ -1046,6 +1047,14 @@ class VegaChartsMixin:
1046
1047
  Streamlit swaps the x-axis and y-axis and the bars display
1047
1048
  horizontally.
1048
1049
 
1050
+ stack : bool, "normalize", "center", "layered", or None
1051
+ Whether to stack the bars. If this is ``None`` (default), uses Vega's
1052
+ default. If this is ``True``, the bars are stacked on top of each other.
1053
+ If this is ``False``, the bars are displayed side by side. If "normalize",
1054
+ the bars are stacked and normalized to 100%. If "center", the bars are
1055
+ stacked around a central axis. If "layered", the bars are stacked on top
1056
+ of one another.
1057
+
1049
1058
  width : int or None
1050
1059
  Desired width of the chart expressed in pixels. If ``width`` is
1051
1060
  ``None`` (default), Streamlit sets the width of the chart to fit
@@ -1139,6 +1148,20 @@ class VegaChartsMixin:
1139
1148
 
1140
1149
  """
1141
1150
 
1151
+ # Offset encodings (used for non-stacked/grouped bar charts) are not supported in Altair < 5.0.0
1152
+ if type_util.is_altair_version_less_than("5.0.0") and stack is False:
1153
+ raise StreamlitAPIException(
1154
+ "Streamlit does not support non-stacked (grouped) bar charts with Altair 4.x. Please upgrade to Version 5."
1155
+ )
1156
+
1157
+ # Check that the stack parameter is valid, raise more informative error message if not
1158
+ VALID_STACK_TYPES = (None, True, False, "normalize", "center", "layered")
1159
+ if stack not in VALID_STACK_TYPES:
1160
+ raise StreamlitAPIException(
1161
+ f'Invalid value for stack parameter: {stack}. Stack must be one of True, False, "normalize", "center", "layered" or None. '
1162
+ "See documentation for `st.bar_chart` [here](https://docs.streamlit.io/develop/api-reference/charts/st.bar_chart) for more information."
1163
+ )
1164
+
1142
1165
  bar_chart_type = (
1143
1166
  ChartType.HORIZONTAL_BAR if horizontal else ChartType.VERTICAL_BAR
1144
1167
  )
@@ -1154,6 +1177,7 @@ class VegaChartsMixin:
1154
1177
  size_from_user=None,
1155
1178
  width=width,
1156
1179
  height=height,
1180
+ stack=stack,
1157
1181
  )
1158
1182
  return cast(
1159
1183
  "DeltaGenerator",
@@ -522,13 +522,13 @@ class ButtonMixin:
522
522
  * A single-character emoji. For example, you can set ``icon="🚨"``
523
523
  or ``icon="🔥"``. Emoji short codes are not supported.
524
524
 
525
- * An icon from the Material Symbols library (outlined style) in the
525
+ * An icon from the Material Symbols library (rounded style) in the
526
526
  format ``":material/icon_name:"`` where "icon_name" is the name
527
527
  of the icon in snake case.
528
528
 
529
529
  For example, ``icon=":material/thumb_up:"`` will display the
530
530
  Thumb Up icon. Find additional icons in the `Material Symbols \
531
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
531
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
532
532
  font library.
533
533
  help : str
534
534
  An optional tooltip that gets displayed when the link is
@@ -167,13 +167,13 @@ class ChatMixin:
167
167
  * A single-character emoji. For example, you can set ``avatar="🧑‍💻"``
168
168
  or ``avatar="🦖"``. Emoji short codes are not supported.
169
169
 
170
- * An icon from the Material Symbols library (outlined style) in the
170
+ * An icon from the Material Symbols library (rounded style) in the
171
171
  format ``":material/icon_name:"`` where "icon_name" is the name
172
172
  of the icon in snake case.
173
173
 
174
174
  For example, ``icon=":material/thumb_up:"`` will display the
175
175
  Thumb Up icon. Find additional icons in the `Material Symbols \
176
- <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Outlined>`_
176
+ <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
177
177
  font library.
178
178
 
179
179
  Returns