streamlit-nightly 1.33.1.dev20240501__py2.py3-none-any.whl → 1.34.1.dev20240503__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/components/v1/custom_component.py +3 -9
- streamlit/delta_generator.py +32 -208
- streamlit/elements/lib/built_in_chart_utils.py +920 -0
- streamlit/elements/utils.py +1 -14
- streamlit/elements/{arrow_altair.py → vega_charts.py} +301 -836
- streamlit/static/asset-manifest.json +5 -5
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/5441.71804c26.chunk.js +1 -0
- streamlit/static/static/js/7483.64f23be7.chunk.js +2 -0
- streamlit/static/static/js/{main.af77b7ba.js → main.3b0201f6.js} +2 -2
- {streamlit_nightly-1.33.1.dev20240501.dist-info → streamlit_nightly-1.34.1.dev20240503.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.33.1.dev20240501.dist-info → streamlit_nightly-1.34.1.dev20240503.dist-info}/RECORD +19 -20
- streamlit/elements/altair_utils.py +0 -40
- streamlit/elements/arrow_vega_lite.py +0 -229
- streamlit/static/static/js/43.c6749504.chunk.js +0 -1
- streamlit/static/static/js/656.7150a933.chunk.js +0 -2
- /streamlit/static/static/css/{43.e3b876c5.chunk.css → 5441.e3b876c5.chunk.css} +0 -0
- /streamlit/static/static/js/{656.7150a933.chunk.js.LICENSE.txt → 7483.64f23be7.chunk.js.LICENSE.txt} +0 -0
- /streamlit/static/static/js/{main.af77b7ba.js.LICENSE.txt → main.3b0201f6.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.33.1.dev20240501.data → streamlit_nightly-1.34.1.dev20240503.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.33.1.dev20240501.dist-info → streamlit_nightly-1.34.1.dev20240503.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.33.1.dev20240501.dist-info → streamlit_nightly-1.34.1.dev20240503.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.33.1.dev20240501.dist-info → streamlit_nightly-1.34.1.dev20240503.dist-info}/top_level.txt +0 -0
@@ -205,11 +205,7 @@ And if you're using Streamlit Cloud, add "pyarrow" to your requirements.txt."""
|
|
205
205
|
widget_value = default
|
206
206
|
elif isinstance(widget_value, ArrowTableProto):
|
207
207
|
widget_value = component_arrow.arrow_proto_to_dataframe(widget_value)
|
208
|
-
|
209
|
-
# widget_value will be either None or whatever the component's most
|
210
|
-
# recent setWidgetValue value is. We coerce None -> NoValue,
|
211
|
-
# because that's what DeltaGenerator._enqueue expects.
|
212
|
-
return widget_value if widget_value is not None else NoValue
|
208
|
+
return widget_value
|
213
209
|
|
214
210
|
# We currently only support writing to st._main, but this will change
|
215
211
|
# when we settle on an improved API in a post-layout world.
|
@@ -217,11 +213,9 @@ And if you're using Streamlit Cloud, add "pyarrow" to your requirements.txt."""
|
|
217
213
|
|
218
214
|
element = Element()
|
219
215
|
return_value = marshall_component(dg, element)
|
220
|
-
result = dg._enqueue(
|
221
|
-
"component_instance", element.component_instance, return_value
|
222
|
-
)
|
223
216
|
|
224
|
-
|
217
|
+
dg._enqueue("component_instance", element.component_instance)
|
218
|
+
return return_value
|
225
219
|
|
226
220
|
def __eq__(self, other) -> bool:
|
227
221
|
"""Equality operator."""
|
streamlit/delta_generator.py
CHANGED
@@ -31,9 +31,10 @@ from typing import (
|
|
31
31
|
NoReturn,
|
32
32
|
TypeVar,
|
33
33
|
cast,
|
34
|
-
overload,
|
35
34
|
)
|
36
35
|
|
36
|
+
from typing_extensions import TypeAlias
|
37
|
+
|
37
38
|
from streamlit import (
|
38
39
|
cli_util,
|
39
40
|
config,
|
@@ -46,10 +47,7 @@ from streamlit import (
|
|
46
47
|
)
|
47
48
|
from streamlit.cursor import Cursor
|
48
49
|
from streamlit.elements.alert import AlertMixin
|
49
|
-
from streamlit.elements.altair_utils import AddRowsMetadata
|
50
50
|
from streamlit.elements.arrow import ArrowMixin
|
51
|
-
from streamlit.elements.arrow_altair import ArrowAltairMixin, prep_data
|
52
|
-
from streamlit.elements.arrow_vega_lite import ArrowVegaLiteMixin
|
53
51
|
from streamlit.elements.balloons import BalloonsMixin
|
54
52
|
from streamlit.elements.bokeh_chart import BokehMixin
|
55
53
|
from streamlit.elements.code import CodeMixin
|
@@ -75,6 +73,7 @@ from streamlit.elements.pyplot import PyplotMixin
|
|
75
73
|
from streamlit.elements.snow import SnowMixin
|
76
74
|
from streamlit.elements.text import TextMixin
|
77
75
|
from streamlit.elements.toast import ToastMixin
|
76
|
+
from streamlit.elements.vega_charts import VegaChartsMixin
|
78
77
|
from streamlit.elements.widgets.button import ButtonMixin
|
79
78
|
from streamlit.elements.widgets.camera_input import CameraInputMixin
|
80
79
|
from streamlit.elements.widgets.chat import ChatMixin
|
@@ -94,35 +93,26 @@ from streamlit.elements.write import WriteMixin
|
|
94
93
|
from streamlit.errors import NoSessionContext, StreamlitAPIException
|
95
94
|
from streamlit.proto import Block_pb2, ForwardMsg_pb2
|
96
95
|
from streamlit.proto.RootContainer_pb2 import RootContainer
|
97
|
-
from streamlit.runtime import caching
|
96
|
+
from streamlit.runtime import caching
|
98
97
|
from streamlit.runtime.scriptrunner import get_script_run_ctx
|
99
|
-
from streamlit.runtime.state import NoValue
|
100
98
|
|
101
99
|
if TYPE_CHECKING:
|
102
100
|
from google.protobuf.message import Message
|
103
101
|
from numpy import typing as npt
|
104
|
-
from pandas import DataFrame
|
102
|
+
from pandas import DataFrame
|
105
103
|
|
106
104
|
from streamlit.elements.arrow import Data
|
105
|
+
from streamlit.elements.lib.built_in_chart_utils import AddRowsMetadata
|
107
106
|
|
108
107
|
|
109
108
|
MAX_DELTA_BYTES: Final[int] = 14 * 1024 * 1024 # 14MB
|
110
109
|
|
111
|
-
# List of Streamlit commands that perform a Pandas "melt" operation on
|
112
|
-
# input dataframes:
|
113
|
-
ARROW_DELTA_TYPES_THAT_MELT_DATAFRAMES: Final = (
|
114
|
-
"arrow_line_chart",
|
115
|
-
"arrow_area_chart",
|
116
|
-
"arrow_bar_chart",
|
117
|
-
"arrow_scatter_chart",
|
118
|
-
)
|
119
|
-
|
120
110
|
Value = TypeVar("Value")
|
121
111
|
DG = TypeVar("DG", bound="DeltaGenerator")
|
122
112
|
|
123
113
|
# Type aliases for Ancestor Block Types
|
124
|
-
BlockType = str
|
125
|
-
AncestorBlockTypes = Iterable[BlockType]
|
114
|
+
BlockType: TypeAlias = str
|
115
|
+
AncestorBlockTypes: TypeAlias = Iterable[BlockType]
|
126
116
|
|
127
117
|
|
128
118
|
_use_warning_has_been_displayed: bool = False
|
@@ -197,8 +187,7 @@ class DeltaGenerator(
|
|
197
187
|
ToastMixin,
|
198
188
|
WriteMixin,
|
199
189
|
ArrowMixin,
|
200
|
-
|
201
|
-
ArrowVegaLiteMixin,
|
190
|
+
VegaChartsMixin,
|
202
191
|
DataEditorMixin,
|
203
192
|
):
|
204
193
|
"""Creator of Delta protobuf messages.
|
@@ -424,75 +413,12 @@ class DeltaGenerator(
|
|
424
413
|
dg = self._active_dg
|
425
414
|
return str(dg._cursor.delta_path) if dg._cursor is not None else "[]"
|
426
415
|
|
427
|
-
@overload
|
428
416
|
def _enqueue(
|
429
417
|
self,
|
430
418
|
delta_type: str,
|
431
419
|
element_proto: Message,
|
432
|
-
return_value: None,
|
433
420
|
add_rows_metadata: AddRowsMetadata | None = None,
|
434
|
-
element_width: int | None = None,
|
435
|
-
element_height: int | None = None,
|
436
421
|
) -> DeltaGenerator:
|
437
|
-
...
|
438
|
-
|
439
|
-
@overload
|
440
|
-
def _enqueue( # type: ignore[misc]
|
441
|
-
self,
|
442
|
-
delta_type: str,
|
443
|
-
element_proto: Message,
|
444
|
-
return_value: type[NoValue],
|
445
|
-
add_rows_metadata: AddRowsMetadata | None = None,
|
446
|
-
element_width: int | None = None,
|
447
|
-
element_height: int | None = None,
|
448
|
-
) -> None:
|
449
|
-
...
|
450
|
-
|
451
|
-
@overload
|
452
|
-
def _enqueue(
|
453
|
-
self,
|
454
|
-
delta_type: str,
|
455
|
-
element_proto: Message,
|
456
|
-
return_value: Value,
|
457
|
-
add_rows_metadata: AddRowsMetadata | None = None,
|
458
|
-
element_width: int | None = None,
|
459
|
-
element_height: int | None = None,
|
460
|
-
) -> Value:
|
461
|
-
...
|
462
|
-
|
463
|
-
@overload
|
464
|
-
def _enqueue(
|
465
|
-
self,
|
466
|
-
delta_type: str,
|
467
|
-
element_proto: Message,
|
468
|
-
return_value: None = None,
|
469
|
-
add_rows_metadata: AddRowsMetadata | None = None,
|
470
|
-
element_width: int | None = None,
|
471
|
-
element_height: int | None = None,
|
472
|
-
) -> DeltaGenerator:
|
473
|
-
...
|
474
|
-
|
475
|
-
@overload
|
476
|
-
def _enqueue(
|
477
|
-
self,
|
478
|
-
delta_type: str,
|
479
|
-
element_proto: Message,
|
480
|
-
return_value: type[NoValue] | Value | None = None,
|
481
|
-
add_rows_metadata: AddRowsMetadata | None = None,
|
482
|
-
element_width: int | None = None,
|
483
|
-
element_height: int | None = None,
|
484
|
-
) -> DeltaGenerator | Value | None:
|
485
|
-
...
|
486
|
-
|
487
|
-
def _enqueue(
|
488
|
-
self,
|
489
|
-
delta_type: str,
|
490
|
-
element_proto: Message,
|
491
|
-
return_value: type[NoValue] | Value | None = None,
|
492
|
-
add_rows_metadata: AddRowsMetadata | None = None,
|
493
|
-
element_width: int | None = None,
|
494
|
-
element_height: int | None = None,
|
495
|
-
) -> DeltaGenerator | Value | None:
|
496
422
|
"""Create NewElement delta, fill it, and enqueue it.
|
497
423
|
|
498
424
|
Parameters
|
@@ -501,21 +427,12 @@ class DeltaGenerator(
|
|
501
427
|
The name of the streamlit method being called
|
502
428
|
element_proto : proto
|
503
429
|
The actual proto in the NewElement type e.g. Alert/Button/Slider
|
504
|
-
return_value : any or None
|
505
|
-
The value to return to the calling script (for widgets)
|
506
|
-
element_width : int or None
|
507
|
-
Desired width for the element
|
508
|
-
element_height : int or None
|
509
|
-
Desired height for the element
|
510
430
|
|
511
431
|
Returns
|
512
432
|
-------
|
513
|
-
DeltaGenerator
|
514
|
-
|
515
|
-
|
516
|
-
element. Otherwise, if the element IS a widget, return the
|
517
|
-
`return_value` parameter.
|
518
|
-
|
433
|
+
DeltaGenerator
|
434
|
+
Return a DeltaGenerator that can be used to modify the newly-created
|
435
|
+
element.
|
519
436
|
"""
|
520
437
|
# Operate on the active DeltaGenerator, in case we're in a `with` block.
|
521
438
|
dg = self._active_dg
|
@@ -531,18 +448,9 @@ class DeltaGenerator(
|
|
531
448
|
# Warn if an element is being changed but the user isn't running the streamlit server.
|
532
449
|
_maybe_print_use_warning()
|
533
450
|
|
534
|
-
# Some elements have a method.__name__ != delta_type in proto.
|
535
|
-
# This really matters for line_chart, bar_chart & area_chart,
|
536
|
-
# since add_rows() relies on method.__name__ == delta_type
|
537
|
-
# TODO: Fix for all elements (or the cache warning above will be wrong)
|
538
|
-
proto_type = delta_type
|
539
|
-
|
540
|
-
if proto_type in ARROW_DELTA_TYPES_THAT_MELT_DATAFRAMES:
|
541
|
-
proto_type = "arrow_vega_lite_chart"
|
542
|
-
|
543
451
|
# Copy the marshalled proto into the overall msg proto
|
544
452
|
msg = ForwardMsg_pb2.ForwardMsg()
|
545
|
-
msg_el_proto = getattr(msg.delta.new_element,
|
453
|
+
msg_el_proto = getattr(msg.delta.new_element, delta_type)
|
546
454
|
msg_el_proto.CopyFrom(element_proto)
|
547
455
|
|
548
456
|
# Only enqueue message and fill in metadata if there's a container.
|
@@ -550,11 +458,6 @@ class DeltaGenerator(
|
|
550
458
|
if dg._root_container is not None and dg._cursor is not None:
|
551
459
|
msg.metadata.delta_path[:] = dg._cursor.delta_path
|
552
460
|
|
553
|
-
if element_width is not None:
|
554
|
-
msg.metadata.element_dimension_spec.width = element_width
|
555
|
-
if element_height is not None:
|
556
|
-
msg.metadata.element_dimension_spec.height = element_height
|
557
|
-
|
558
461
|
_enqueue_message(msg)
|
559
462
|
msg_was_enqueued = True
|
560
463
|
|
@@ -579,7 +482,7 @@ class DeltaGenerator(
|
|
579
482
|
# no-op from the point of view of the app.
|
580
483
|
output_dg = dg
|
581
484
|
|
582
|
-
# Save message for replay if we're called from within @st.
|
485
|
+
# Save message for replay if we're called from within @st.cache_data or @st.cache_resource
|
583
486
|
caching.save_element_message(
|
584
487
|
delta_type,
|
585
488
|
element_proto,
|
@@ -588,7 +491,7 @@ class DeltaGenerator(
|
|
588
491
|
returned_dg_id=output_dg.id,
|
589
492
|
)
|
590
493
|
|
591
|
-
return
|
494
|
+
return output_dg
|
592
495
|
|
593
496
|
def _block(
|
594
497
|
self,
|
@@ -732,22 +635,20 @@ class DeltaGenerator(
|
|
732
635
|
|
733
636
|
# When doing _arrow_add_rows on an element that does not already have data
|
734
637
|
# (for example, st.line_chart() without any args), call the original
|
735
|
-
# st.
|
638
|
+
# st.foo() element with new data instead of doing a _arrow_add_rows().
|
736
639
|
if (
|
737
|
-
self._cursor.props
|
640
|
+
"add_rows_metadata" in self._cursor.props
|
641
|
+
and self._cursor.props["add_rows_metadata"]
|
738
642
|
and self._cursor.props["add_rows_metadata"].last_index is None
|
739
643
|
):
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
st_method_name = self._cursor.props["delta_type"].replace("arrow_", "")
|
744
|
-
st_method = getattr(self, st_method_name)
|
644
|
+
st_method = getattr(
|
645
|
+
self, self._cursor.props["add_rows_metadata"].chart_command
|
646
|
+
)
|
745
647
|
st_method(data, **kwargs)
|
746
648
|
return None
|
747
649
|
|
748
650
|
new_data, self._cursor.props["add_rows_metadata"] = _prep_data_for_add_rows(
|
749
651
|
data,
|
750
|
-
self._cursor.props["delta_type"],
|
751
652
|
self._cursor.props["add_rows_metadata"],
|
752
653
|
)
|
753
654
|
|
@@ -797,98 +698,21 @@ def get_last_dg_added_to_context_stack() -> DeltaGenerator | None:
|
|
797
698
|
|
798
699
|
def _prep_data_for_add_rows(
|
799
700
|
data: Data,
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
out_data: Data
|
804
|
-
|
805
|
-
# For some delta types we have to reshape the data structure
|
806
|
-
# otherwise the input data and the actual data used
|
807
|
-
# by vega_lite will be different, and it will throw an error.
|
808
|
-
if delta_type in ARROW_DELTA_TYPES_THAT_MELT_DATAFRAMES:
|
809
|
-
import pandas as pd
|
810
|
-
|
811
|
-
df = cast(pd.DataFrame, type_util.convert_anything_to_df(data))
|
812
|
-
|
813
|
-
# Make range indices start at last_index.
|
814
|
-
if isinstance(df.index, pd.RangeIndex):
|
815
|
-
old_step = _get_pandas_index_attr(df, "step")
|
816
|
-
|
817
|
-
# We have to drop the predefined index
|
818
|
-
df = df.reset_index(drop=True)
|
819
|
-
|
820
|
-
old_stop = _get_pandas_index_attr(df, "stop")
|
821
|
-
|
822
|
-
if old_step is None or old_stop is None:
|
823
|
-
raise StreamlitAPIException(
|
824
|
-
"'RangeIndex' object has no attribute 'step'"
|
825
|
-
)
|
826
|
-
|
827
|
-
start = add_rows_metadata.last_index + old_step
|
828
|
-
stop = add_rows_metadata.last_index + old_step + old_stop
|
829
|
-
|
830
|
-
df.index = pd.RangeIndex(start=start, stop=stop, step=old_step)
|
831
|
-
add_rows_metadata.last_index = stop - 1
|
832
|
-
|
833
|
-
out_data, *_ = prep_data(df, **add_rows_metadata.columns)
|
834
|
-
|
835
|
-
else:
|
701
|
+
add_rows_metadata: AddRowsMetadata | None,
|
702
|
+
) -> tuple[Data, AddRowsMetadata | None]:
|
703
|
+
if not add_rows_metadata:
|
836
704
|
# When calling add_rows on st.table or st.dataframe we want styles to pass through.
|
837
|
-
|
838
|
-
|
839
|
-
return out_data, add_rows_metadata
|
840
|
-
|
841
|
-
|
842
|
-
def _get_pandas_index_attr(
|
843
|
-
data: DataFrame | Series,
|
844
|
-
attr: str,
|
845
|
-
) -> Any | None:
|
846
|
-
return getattr(data.index, attr, None)
|
847
|
-
|
848
|
-
|
849
|
-
@overload
|
850
|
-
def _value_or_dg(value: None, dg: DG) -> DG:
|
851
|
-
...
|
852
|
-
|
853
|
-
|
854
|
-
@overload
|
855
|
-
def _value_or_dg(value: type[NoValue], dg: DG) -> None: # type: ignore[misc]
|
856
|
-
...
|
705
|
+
return type_util.convert_anything_to_df(data, allow_styler=True), None
|
857
706
|
|
707
|
+
# If add_rows_metadata is set, it indicates that the add_rows used called
|
708
|
+
# on a chart based on our built-in chart commands.
|
858
709
|
|
859
|
-
|
860
|
-
|
861
|
-
#
|
862
|
-
|
863
|
-
# mypy complains. Hence, the ignore-comment above. But, in practice, since
|
864
|
-
# the overload above is more specific, and is matched first, there is no
|
865
|
-
# actual overlap. The `Value` type here is thus narrowed to the cases
|
866
|
-
# where value is neither None nor NoValue.
|
867
|
-
|
868
|
-
# The ignore-comment should thus be fine.
|
869
|
-
...
|
870
|
-
|
871
|
-
|
872
|
-
def _value_or_dg(
|
873
|
-
value: type[NoValue] | Value | None,
|
874
|
-
dg: DG,
|
875
|
-
) -> DG | Value | None:
|
876
|
-
"""Return either value, or None, or dg.
|
877
|
-
|
878
|
-
This is needed because Widgets have meaningful return values. This is
|
879
|
-
unlike other elements, which always return None. Then we internally replace
|
880
|
-
that None with a DeltaGenerator instance.
|
881
|
-
|
882
|
-
However, sometimes a widget may want to return None, and in this case it
|
883
|
-
should not be replaced by a DeltaGenerator. So we have a special NoValue
|
884
|
-
object that gets replaced by None.
|
710
|
+
# For built-in chart commands we have to reshape the data structure
|
711
|
+
# otherwise the input data and the actual data used
|
712
|
+
# by vega_lite will be different, and it will throw an error.
|
713
|
+
from streamlit.elements.lib.built_in_chart_utils import prep_chart_data_for_add_rows
|
885
714
|
|
886
|
-
|
887
|
-
if value is NoValue:
|
888
|
-
return None
|
889
|
-
if value is None:
|
890
|
-
return dg
|
891
|
-
return cast(Value, value)
|
715
|
+
return prep_chart_data_for_add_rows(data, add_rows_metadata)
|
892
716
|
|
893
717
|
|
894
718
|
def _enqueue_message(msg: ForwardMsg_pb2.ForwardMsg) -> None:
|