streamlit 1.49.1__py3-none-any.whl → 1.51.0__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/__init__.py +4 -1
- streamlit/column_config.py +2 -0
- streamlit/commands/navigation.py +7 -7
- streamlit/commands/page_config.py +4 -6
- streamlit/components/v1/custom_component.py +17 -42
- streamlit/components/v2/__init__.py +458 -0
- streamlit/components/v2/bidi_component/__init__.py +20 -0
- streamlit/components/v2/bidi_component/constants.py +29 -0
- streamlit/components/v2/bidi_component/main.py +386 -0
- streamlit/components/v2/bidi_component/serialization.py +265 -0
- streamlit/components/v2/bidi_component/state.py +92 -0
- streamlit/components/v2/component_definition_resolver.py +143 -0
- streamlit/components/v2/component_file_watcher.py +403 -0
- streamlit/components/v2/component_manager.py +431 -0
- streamlit/components/v2/component_manifest_handler.py +122 -0
- streamlit/components/v2/component_path_utils.py +245 -0
- streamlit/components/v2/component_registry.py +409 -0
- streamlit/components/v2/get_bidi_component_manager.py +51 -0
- streamlit/components/v2/manifest_scanner.py +615 -0
- streamlit/components/v2/presentation.py +198 -0
- streamlit/components/v2/types.py +324 -0
- streamlit/config.py +741 -32
- streamlit/config_option.py +4 -1
- streamlit/config_util.py +650 -1
- streamlit/connections/base_connection.py +4 -2
- streamlit/dataframe_util.py +18 -10
- streamlit/delta_generator.py +8 -7
- streamlit/delta_generator_singletons.py +3 -1
- streamlit/deprecation_util.py +17 -6
- streamlit/elements/arrow.py +90 -42
- streamlit/elements/deck_gl_json_chart.py +98 -39
- streamlit/elements/dialog_decorator.py +2 -1
- streamlit/elements/exception.py +3 -1
- streamlit/elements/form.py +6 -6
- streamlit/elements/graphviz_chart.py +24 -9
- streamlit/elements/heading.py +3 -5
- streamlit/elements/iframe.py +0 -2
- streamlit/elements/image.py +12 -13
- streamlit/elements/layouts.py +89 -22
- streamlit/elements/lib/built_in_chart_utils.py +95 -31
- streamlit/elements/lib/color_util.py +8 -18
- streamlit/elements/lib/column_config_utils.py +9 -8
- streamlit/elements/lib/column_types.py +595 -148
- streamlit/elements/lib/dialog.py +3 -2
- streamlit/elements/lib/image_utils.py +3 -5
- streamlit/elements/lib/layout_utils.py +50 -13
- streamlit/elements/lib/mutable_status_container.py +2 -2
- streamlit/elements/lib/options_selector_utils.py +2 -2
- streamlit/elements/lib/pandas_styler_utils.py +30 -14
- streamlit/elements/lib/utils.py +21 -9
- streamlit/elements/map.py +81 -40
- streamlit/elements/media.py +7 -7
- streamlit/elements/metric.py +11 -35
- streamlit/elements/pdf.py +2 -4
- streamlit/elements/plotly_chart.py +142 -26
- streamlit/elements/progress.py +2 -4
- streamlit/elements/pyplot.py +6 -6
- streamlit/elements/space.py +113 -0
- streamlit/elements/vega_charts.py +400 -143
- streamlit/elements/widgets/audio_input.py +52 -4
- streamlit/elements/widgets/button.py +29 -29
- streamlit/elements/widgets/button_group.py +33 -6
- streamlit/elements/widgets/camera_input.py +3 -4
- streamlit/elements/widgets/chat.py +7 -0
- streamlit/elements/widgets/checkbox.py +1 -0
- streamlit/elements/widgets/color_picker.py +1 -0
- streamlit/elements/widgets/data_editor.py +34 -29
- streamlit/elements/widgets/file_uploader.py +6 -10
- streamlit/elements/widgets/multiselect.py +14 -3
- streamlit/elements/widgets/number_input.py +5 -4
- streamlit/elements/widgets/radio.py +10 -2
- streamlit/elements/widgets/select_slider.py +8 -4
- streamlit/elements/widgets/selectbox.py +9 -2
- streamlit/elements/widgets/slider.py +38 -41
- streamlit/elements/widgets/text_widgets.py +6 -0
- streamlit/elements/widgets/time_widgets.py +15 -12
- streamlit/elements/write.py +28 -23
- streamlit/emojis.py +1 -1
- streamlit/errors.py +115 -0
- streamlit/git_util.py +65 -43
- streamlit/hello/hello.py +8 -0
- streamlit/hello/utils.py +2 -1
- streamlit/material_icon_names.py +1 -1
- streamlit/navigation/page.py +4 -1
- streamlit/proto/ArrowData_pb2.py +27 -0
- streamlit/proto/ArrowData_pb2.pyi +46 -0
- streamlit/proto/Arrow_pb2.py +10 -8
- streamlit/proto/Arrow_pb2.pyi +31 -2
- streamlit/proto/AudioInput_pb2.py +2 -2
- streamlit/proto/AudioInput_pb2.pyi +6 -2
- streamlit/proto/BidiComponent_pb2.py +34 -0
- streamlit/proto/BidiComponent_pb2.pyi +153 -0
- streamlit/proto/Block_pb2.py +11 -11
- streamlit/proto/Block_pb2.pyi +9 -1
- streamlit/proto/DeckGlJsonChart_pb2.py +10 -4
- streamlit/proto/DeckGlJsonChart_pb2.pyi +9 -3
- streamlit/proto/Element_pb2.py +5 -3
- streamlit/proto/Element_pb2.pyi +14 -4
- streamlit/proto/HeightConfig_pb2.py +2 -2
- streamlit/proto/HeightConfig_pb2.pyi +6 -3
- streamlit/proto/NewSession_pb2.py +18 -16
- streamlit/proto/NewSession_pb2.pyi +158 -6
- streamlit/proto/PlotlyChart_pb2.py +8 -6
- streamlit/proto/PlotlyChart_pb2.pyi +3 -1
- streamlit/proto/Space_pb2.py +27 -0
- streamlit/proto/Space_pb2.pyi +42 -0
- streamlit/proto/WidgetStates_pb2.py +2 -2
- streamlit/proto/WidgetStates_pb2.pyi +13 -3
- streamlit/proto/WidthConfig_pb2.py +2 -2
- streamlit/proto/WidthConfig_pb2.pyi +6 -3
- streamlit/runtime/app_session.py +45 -6
- streamlit/runtime/caching/cache_data_api.py +4 -4
- streamlit/runtime/caching/cache_errors.py +4 -1
- streamlit/runtime/caching/cache_resource_api.py +3 -2
- streamlit/runtime/caching/cache_utils.py +2 -1
- streamlit/runtime/caching/cached_message_replay.py +3 -3
- streamlit/runtime/caching/hashing.py +3 -4
- streamlit/runtime/caching/legacy_cache_api.py +2 -1
- streamlit/runtime/connection_factory.py +1 -3
- streamlit/runtime/forward_msg_queue.py +4 -1
- streamlit/runtime/fragment.py +2 -1
- streamlit/runtime/memory_media_file_storage.py +1 -1
- streamlit/runtime/metrics_util.py +6 -2
- streamlit/runtime/runtime.py +14 -0
- streamlit/runtime/scriptrunner/exec_code.py +2 -1
- streamlit/runtime/scriptrunner/script_runner.py +2 -2
- streamlit/runtime/scriptrunner_utils/script_run_context.py +3 -6
- streamlit/runtime/secrets.py +2 -4
- streamlit/runtime/session_manager.py +3 -1
- streamlit/runtime/state/common.py +30 -5
- streamlit/runtime/state/presentation.py +85 -0
- streamlit/runtime/state/safe_session_state.py +2 -2
- streamlit/runtime/state/session_state.py +220 -16
- streamlit/runtime/state/widgets.py +19 -3
- streamlit/runtime/theme_util.py +148 -0
- streamlit/runtime/websocket_session_manager.py +3 -1
- streamlit/source_util.py +2 -2
- streamlit/static/index.html +2 -2
- streamlit/static/manifest.json +244 -227
- streamlit/static/static/css/{index.C8X8rNzw.css → index.BpABIXK9.css} +1 -1
- streamlit/static/static/css/index.DgR7E2CV.css +1 -0
- streamlit/static/static/js/{ErrorOutline.esm.DcGrhbBP.js → ErrorOutline.esm.YoJdlW1p.js} +1 -1
- streamlit/static/static/js/{FileDownload.esm.DgBvV6Pq.js → FileDownload.esm.Ddx8VEYy.js} +1 -1
- streamlit/static/static/js/{FileHelper.M6AAaeuA.js → FileHelper.90EtOmj9.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.DHh1GFzm.js → FormClearHelper.BB1Km6eP.js} +1 -1
- streamlit/static/static/js/InputInstructions.jhH15PqV.js +1 -0
- streamlit/static/static/js/{Particles.DDVT-6Qc.js → Particles.DUsputn1.js} +1 -1
- streamlit/static/static/js/{ProgressBar.BEY0cXXV.js → ProgressBar.DLY8H6nE.js} +2 -2
- streamlit/static/static/js/Toolbar.D8nHCkuz.js +1 -0
- streamlit/static/static/js/{base-input.CK3UVGp1.js → base-input.CJGiNqed.js} +3 -3
- streamlit/static/static/js/{checkbox.D8W881TL.js → checkbox.Cpdd482O.js} +1 -1
- streamlit/static/static/js/{createSuper.B6W-Dh9S.js → createSuper.CuQIogbW.js} +1 -1
- streamlit/static/static/js/data-grid-overlay-editor.2Ufgxc6y.js +1 -0
- streamlit/static/static/js/{downloader.DiKpuU_S.js → downloader.CN0K7xlu.js} +1 -1
- streamlit/static/static/js/{es6.B8zRNPZ-.js → es6.BJcsVXQ0.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.DIewJmmh.js → iframeResizer.contentWindow.XzUvQqcZ.js} +1 -1
- streamlit/static/static/js/index.B1ZQh4P1.js +1 -0
- streamlit/static/static/js/index.BKstZk0M.js +27 -0
- streamlit/static/static/js/{index.Bte_9Lyq.js → index.BMcFsUee.js} +1 -1
- streamlit/static/static/js/{index.qhs54UAB.js → index.BR-IdcTb.js} +1 -1
- streamlit/static/static/js/{index.CejBxbg1.js → index.B_dWA3vd.js} +1 -1
- streamlit/static/static/js/{index.D5naqx-J.js → index.BgnZEMVh.js} +1 -1
- streamlit/static/static/js/{index.C7fRKRs4.js → index.BohqXifI.js} +1 -1
- streamlit/static/static/js/{index.cnnXF7xQ.js → index.Br5nxKNj.js} +1 -1
- streamlit/static/static/js/index.BrIKVbNc.js +3 -0
- streamlit/static/static/js/index.BtWUPzle.js +1 -0
- streamlit/static/static/js/index.C0RLraek.js +1 -0
- streamlit/static/static/js/{index.CP5TD2z1.js → index.CAIjskgG.js} +1 -1
- streamlit/static/static/js/{index.CD8HuT3N.js → index.CAj-7vWz.js} +135 -162
- streamlit/static/static/js/{index.DtYN2x4k.js → index.CMtEit2O.js} +1 -1
- streamlit/static/static/js/index.CkRlykEE.js +12 -0
- streamlit/static/static/js/{index.Ts_0SdB9.js → index.CmN3FXfI.js} +2 -2
- streamlit/static/static/js/{index.BnEpvLEz.js → index.CwbFI1_-.js} +1 -1
- streamlit/static/static/js/{index.CcJf6BCU.js → index.CxIUUfab.js} +27 -27
- streamlit/static/static/js/index.D2KPNy7e.js +1 -0
- streamlit/static/static/js/{index.Ch7MBCx0.js → index.D3GPA5k4.js} +47 -47
- streamlit/static/static/js/{index.ho6NIXGl.js → index.DGAh7DMq.js} +1 -1
- streamlit/static/static/js/index.DKb_NvmG.js +197 -0
- streamlit/static/static/js/{index.CvYYtxD_.js → index.DMqgUYKq.js} +1 -1
- streamlit/static/static/js/{index.zecpGxtj.js → index.DOFlg3dS.js} +1 -1
- streamlit/static/static/js/{index.B9mjBcgE.js → index.DPUXkcQL.js} +1 -1
- streamlit/static/static/js/index.DX1xY89g.js +1 -0
- streamlit/static/static/js/index.DYATBCsq.js +2 -0
- streamlit/static/static/js/{index.D2-atlaQ.js → index.DaSmGJ76.js} +3 -3
- streamlit/static/static/js/index.Dd7bMeLP.js +1 -0
- streamlit/static/static/js/{index.4eF4NxG2.js → index.DjmmgI5U.js} +1 -1
- streamlit/static/static/js/index.Dq56CyM2.js +1 -0
- streamlit/static/static/js/index.DuiXaS5_.js +7 -0
- streamlit/static/static/js/index.DvFidMLe.js +2 -0
- streamlit/static/static/js/{index.452cqrrL.js → index.DwkhC5Pc.js} +1 -1
- streamlit/static/static/js/{index.Dk4C7X3i.js → index.Q-3sFn1v.js} +1 -1
- streamlit/static/static/js/{index.CjXWwH-y.js → index.QJ5QO9sJ.js} +1 -1
- streamlit/static/static/js/{index.B6U8LQo3.js → index.VwTaeety.js} +1 -1
- streamlit/static/static/js/index.YOqQbeX8.js +1 -0
- streamlit/static/static/js/{input.nzVJphXi.js → input.D4MN_FzN.js} +1 -1
- streamlit/static/static/js/{memory.CjCgTQz3.js → memory.DrZjtdGT.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.DaRFzZEO.js → number-overlay-editor.DRwAw1In.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.DgiPnZ9N.js → possibleConstructorReturn.exeeJQEP.js} +1 -1
- streamlit/static/static/js/record.B-tDciZb.js +1 -0
- streamlit/static/static/js/{sandbox.mithfq7Z.js → sandbox.ClO3IuUr.js} +1 -1
- streamlit/static/static/js/{timepicker.Dbl5KFh6.js → timepicker.DAhu-vcF.js} +4 -4
- streamlit/static/static/js/{toConsumableArray.D-Dx88BQ.js → toConsumableArray.DNbljYEC.js} +1 -1
- streamlit/static/static/js/{uniqueId.Bh26R_3S.js → uniqueId.oG4Gvj1v.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.DeK-QJpD.js → useBasicWidgetState.D6sOH6oI.js} +1 -1
- streamlit/static/static/js/{useTextInputAutoExpand.4iAdLWD-.js → useTextInputAutoExpand.4u3_GcuN.js} +2 -2
- streamlit/static/static/js/{useUpdateUiValue.CmT7_nJN.js → useUpdateUiValue.F2R3eTeR.js} +1 -1
- streamlit/static/static/js/wavesurfer.esm.vI8Eid4k.js +73 -0
- streamlit/static/static/js/withFullScreenWrapper.zothJIsI.js +1 -0
- streamlit/static/static/media/MaterialSymbols-Rounded.C7IFxh57.woff2 +0 -0
- streamlit/string_util.py +56 -1
- streamlit/testing/v1/app_test.py +2 -2
- streamlit/testing/v1/element_tree.py +23 -9
- streamlit/testing/v1/util.py +2 -2
- streamlit/type_util.py +3 -4
- streamlit/url_util.py +1 -3
- streamlit/user_info.py +1 -2
- streamlit/util.py +3 -1
- streamlit/watcher/event_based_path_watcher.py +23 -12
- streamlit/watcher/local_sources_watcher.py +11 -1
- streamlit/watcher/path_watcher.py +9 -6
- streamlit/watcher/polling_path_watcher.py +4 -1
- streamlit/watcher/util.py +2 -2
- streamlit/web/bootstrap.py +0 -31
- streamlit/web/cli.py +51 -22
- streamlit/web/server/bidi_component_request_handler.py +193 -0
- streamlit/web/server/component_file_utils.py +97 -0
- streamlit/web/server/component_request_handler.py +8 -21
- streamlit/web/server/oidc_mixin.py +3 -1
- streamlit/web/server/routes.py +18 -5
- streamlit/web/server/server.py +10 -0
- streamlit/web/server/server_util.py +3 -1
- streamlit/web/server/upload_file_request_handler.py +3 -1
- {streamlit-1.49.1.dist-info → streamlit-1.51.0.dist-info}/METADATA +4 -5
- {streamlit-1.49.1.dist-info → streamlit-1.51.0.dist-info}/RECORD +238 -209
- streamlit/static/static/css/index.COe1010n.css +0 -1
- streamlit/static/static/js/Hooks.DGu1od_L.js +0 -1
- streamlit/static/static/js/InputInstructions.z6sVgyYt.js +0 -1
- streamlit/static/static/js/Toolbar.DSnK1fUh.js +0 -1
- streamlit/static/static/js/data-grid-overlay-editor.DRTHOydk.js +0 -1
- streamlit/static/static/js/index.BXYmrqnf.js +0 -1
- streamlit/static/static/js/index.B_8AnktO.js +0 -1
- streamlit/static/static/js/index.Bl7zGQSh.js +0 -7
- streamlit/static/static/js/index.BnJIOYn9.js +0 -73
- streamlit/static/static/js/index.C1HcTl5K.js +0 -1
- streamlit/static/static/js/index.C7lSmSOP.js +0 -1
- streamlit/static/static/js/index.C_tmcx4B.js +0 -1
- streamlit/static/static/js/index.D3K5nOu9.js +0 -197
- streamlit/static/static/js/index.DkKT3LUI.js +0 -1
- streamlit/static/static/js/index.MTPPBDHk.js +0 -2
- streamlit/static/static/js/index.pqW9AMJD.js +0 -3
- streamlit/static/static/js/index.urHgTgMQ.js +0 -12
- streamlit/static/static/js/index.wzkv_11M.js +0 -1
- streamlit/static/static/js/index.yF5AncHY.js +0 -1
- streamlit/static/static/js/withFullScreenWrapper.DLp1ENGm.js +0 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.CBxVaFdk.woff2 +0 -0
- {streamlit-1.49.1.data → streamlit-1.51.0.data}/scripts/streamlit.cmd +0 -0
- {streamlit-1.49.1.dist-info → streamlit-1.51.0.dist-info}/WHEEL +0 -0
- {streamlit-1.49.1.dist-info → streamlit-1.51.0.dist-info}/entry_points.txt +0 -0
- {streamlit-1.49.1.dist-info → streamlit-1.51.0.dist-info}/top_level.txt +0 -0
|
@@ -18,6 +18,7 @@ from __future__ import annotations
|
|
|
18
18
|
|
|
19
19
|
import json
|
|
20
20
|
import re
|
|
21
|
+
import threading
|
|
21
22
|
from contextlib import nullcontext
|
|
22
23
|
from dataclasses import dataclass
|
|
23
24
|
from typing import (
|
|
@@ -25,15 +26,20 @@ from typing import (
|
|
|
25
26
|
Any,
|
|
26
27
|
Final,
|
|
27
28
|
Literal,
|
|
29
|
+
TypeAlias,
|
|
28
30
|
TypedDict,
|
|
29
31
|
Union,
|
|
30
32
|
cast,
|
|
31
33
|
overload,
|
|
32
34
|
)
|
|
33
35
|
|
|
34
|
-
from typing_extensions import Required
|
|
36
|
+
from typing_extensions import Required
|
|
35
37
|
|
|
36
38
|
from streamlit import dataframe_util, type_util
|
|
39
|
+
from streamlit.deprecation_util import (
|
|
40
|
+
make_deprecated_name_warning,
|
|
41
|
+
show_deprecation_warning,
|
|
42
|
+
)
|
|
37
43
|
from streamlit.elements.lib import dicttools
|
|
38
44
|
from streamlit.elements.lib.built_in_chart_utils import (
|
|
39
45
|
AddRowsMetadata,
|
|
@@ -43,6 +49,13 @@ from streamlit.elements.lib.built_in_chart_utils import (
|
|
|
43
49
|
maybe_raise_stack_warning,
|
|
44
50
|
)
|
|
45
51
|
from streamlit.elements.lib.form_utils import current_form_id
|
|
52
|
+
from streamlit.elements.lib.layout_utils import (
|
|
53
|
+
Height,
|
|
54
|
+
LayoutConfig,
|
|
55
|
+
Width,
|
|
56
|
+
validate_height,
|
|
57
|
+
validate_width,
|
|
58
|
+
)
|
|
46
59
|
from streamlit.elements.lib.policies import check_widget_policies
|
|
47
60
|
from streamlit.elements.lib.utils import Key, compute_and_register_element_id, to_key
|
|
48
61
|
from streamlit.errors import StreamlitAPIException
|
|
@@ -104,6 +117,8 @@ AltairChart: TypeAlias = Union[
|
|
|
104
117
|
"alt.VConcatChart",
|
|
105
118
|
]
|
|
106
119
|
|
|
120
|
+
_altair_globals_lock = threading.Lock()
|
|
121
|
+
|
|
107
122
|
|
|
108
123
|
class VegaLiteState(TypedDict, total=False):
|
|
109
124
|
"""
|
|
@@ -321,7 +336,7 @@ def _marshall_chart_data(
|
|
|
321
336
|
dataset = proto.datasets.add()
|
|
322
337
|
dataset.name = str(dataset_name)
|
|
323
338
|
dataset.has_name = True
|
|
324
|
-
# The ID transformer (
|
|
339
|
+
# The ID transformer (_to_arrow_dataset function registered before conversion to dict)
|
|
325
340
|
# already serializes the data into Arrow IPC format (bytes) when the Altair object
|
|
326
341
|
# gets converted into the vega-lite spec dict.
|
|
327
342
|
# If its already in bytes, we don't need to serialize it here again.
|
|
@@ -362,41 +377,46 @@ def _convert_altair_to_vega_lite_spec(
|
|
|
362
377
|
"""Convert an Altair chart object to a Vega-Lite chart spec."""
|
|
363
378
|
import altair as alt
|
|
364
379
|
|
|
380
|
+
# alt.themes was deprecated in Altair 5.5.0 in favor of alt.theme
|
|
381
|
+
if type_util.is_altair_version_less_than("5.5.0"):
|
|
382
|
+
alt_theme = alt.themes # ty: ignore[unresolved-attribute]
|
|
383
|
+
else:
|
|
384
|
+
alt_theme = alt.theme
|
|
385
|
+
|
|
386
|
+
# This is where we'll store Arrow-serialized versions of the chart data.
|
|
387
|
+
# This happens in _to_arrow_dataset().
|
|
388
|
+
datasets: dict[str, Any] = {}
|
|
389
|
+
|
|
365
390
|
# Normally altair_chart.to_dict() would transform the dataframe used by the
|
|
366
391
|
# chart into an array of dictionaries. To avoid that, we install a
|
|
367
392
|
# transformer that replaces datasets with a reference by the object id of
|
|
368
393
|
# the dataframe. We then fill in the dataset manually later on.
|
|
394
|
+
#
|
|
395
|
+
# Note: it's OK to re-register this every time we run this function since
|
|
396
|
+
# transformers are stored in a dict. So there's no duplication.
|
|
397
|
+
#
|
|
398
|
+
# type: ignore[arg-type,attr-defined,unused-ignore]
|
|
399
|
+
alt.data_transformers.register("to_arrow_dataset", _to_arrow_dataset)
|
|
400
|
+
|
|
401
|
+
# Settings like alt.theme.enable and alt.data_transformers.enable are global to all
|
|
402
|
+
# threads. So this lock makes sure that whatever we set those to only apply to the
|
|
403
|
+
# current thread.
|
|
404
|
+
with _altair_globals_lock:
|
|
405
|
+
# The default altair theme has some width/height defaults defined
|
|
406
|
+
# which are not useful for Streamlit. Therefore, we change the theme to
|
|
407
|
+
# "none" to avoid those defaults.
|
|
408
|
+
theme_context = (
|
|
409
|
+
alt_theme.enable("none") if alt_theme.active == "default" else nullcontext()
|
|
410
|
+
)
|
|
369
411
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
"""Altair data transformer that serializes the data,
|
|
374
|
-
creates a stable name based on the hash of the data,
|
|
375
|
-
stores the bytes into the datasets mapping and
|
|
376
|
-
returns this name to have it be used in Altair.
|
|
377
|
-
"""
|
|
378
|
-
# Already serialize the data to be able to create a stable
|
|
379
|
-
# dataset name:
|
|
380
|
-
data_bytes = dataframe_util.convert_anything_to_arrow_bytes(data)
|
|
381
|
-
# Use the md5 hash of the data as the name:
|
|
382
|
-
name = calc_md5(str(data_bytes))
|
|
383
|
-
|
|
384
|
-
datasets[name] = data_bytes
|
|
385
|
-
return {"name": name}
|
|
386
|
-
|
|
387
|
-
alt.data_transformers.register("id", id_transform) # type: ignore[arg-type,attr-defined,unused-ignore]
|
|
388
|
-
|
|
389
|
-
# alt.themes was deprecated in Altair 5.5.0 in favor of alt.theme
|
|
390
|
-
alt_theme = (
|
|
391
|
-
alt.themes if type_util.is_altair_version_less_than("5.5.0") else alt.theme # ty: ignore[unresolved-attribute]
|
|
392
|
-
)
|
|
412
|
+
data_transformer = alt.data_transformers.enable(
|
|
413
|
+
"to_arrow_dataset", datasets=datasets
|
|
414
|
+
)
|
|
393
415
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
with alt.data_transformers.enable("id"): # type: ignore[attr-defined,unused-ignore]
|
|
399
|
-
chart_dict = altair_chart.to_dict()
|
|
416
|
+
with theme_context: # ty: ignore[invalid-context-manager]
|
|
417
|
+
# type: ignore[attr-defined,unused-ignore]
|
|
418
|
+
with data_transformer: # ty: ignore[invalid-context-manager]
|
|
419
|
+
chart_dict = altair_chart.to_dict()
|
|
400
420
|
|
|
401
421
|
# Put datasets back into the chart dict:
|
|
402
422
|
chart_dict["datasets"] = datasets
|
|
@@ -596,9 +616,9 @@ class VegaChartsMixin:
|
|
|
596
616
|
x_label: str | None = None,
|
|
597
617
|
y_label: str | None = None,
|
|
598
618
|
color: str | Color | list[Color] | None = None,
|
|
599
|
-
width:
|
|
600
|
-
height:
|
|
601
|
-
use_container_width: bool =
|
|
619
|
+
width: Width = "stretch",
|
|
620
|
+
height: Height = "content",
|
|
621
|
+
use_container_width: bool | None = None,
|
|
602
622
|
) -> DeltaGenerator:
|
|
603
623
|
"""Display a line chart.
|
|
604
624
|
|
|
@@ -607,9 +627,6 @@ class VegaChartsMixin:
|
|
|
607
627
|
the chart's Altair spec. As a result this is easier to use for many
|
|
608
628
|
"just plot this" scenarios, while being less customizable.
|
|
609
629
|
|
|
610
|
-
If ``st.line_chart`` does not guess the data specification
|
|
611
|
-
correctly, try specifying your desired chart using ``st.altair_chart``.
|
|
612
|
-
|
|
613
630
|
Parameters
|
|
614
631
|
----------
|
|
615
632
|
data : Anything supported by st.dataframe
|
|
@@ -680,27 +697,46 @@ class VegaChartsMixin:
|
|
|
680
697
|
You can set the default colors in the ``theme.chartCategoryColors``
|
|
681
698
|
configuration option.
|
|
682
699
|
|
|
683
|
-
width :
|
|
684
|
-
|
|
685
|
-
``None`` (default), Streamlit sets the width of the chart to fit
|
|
686
|
-
its contents according to the plotting library, up to the width of
|
|
687
|
-
the parent container. If ``width`` is greater than the width of the
|
|
688
|
-
parent container, Streamlit sets the chart width to match the width
|
|
689
|
-
of the parent container.
|
|
700
|
+
width : "stretch", "content", or int
|
|
701
|
+
The width of the chart element. This can be one of the following:
|
|
690
702
|
|
|
691
|
-
|
|
703
|
+
- ``"stretch"`` (default): The width of the element matches the
|
|
704
|
+
width of the parent container.
|
|
705
|
+
- ``"content"``: The width of the element matches the width of its
|
|
706
|
+
content, but doesn't exceed the width of the parent container.
|
|
707
|
+
- An integer specifying the width in pixels: The element has a
|
|
708
|
+
fixed width. If the specified width is greater than the width of
|
|
709
|
+
the parent container, the width of the element matches the width
|
|
710
|
+
of the parent container.
|
|
711
|
+
|
|
712
|
+
height : "content", "stretch", or int
|
|
713
|
+
The height of the chart element. This can be one of the following:
|
|
714
|
+
|
|
715
|
+
- ``"content"`` (default): The height of the element matches the
|
|
716
|
+
height of its content.
|
|
717
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
718
|
+
its content or the height of the parent container, whichever is
|
|
719
|
+
larger. If the element is not in a parent container, the height
|
|
720
|
+
of the element matches the height of its content.
|
|
721
|
+
- An integer specifying the height in pixels: The element has a
|
|
722
|
+
fixed height. If the content is larger than the specified
|
|
723
|
+
height, scrolling is enabled.
|
|
692
724
|
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
its contents according to the plotting library.
|
|
725
|
+
use_container_width : bool or None
|
|
726
|
+
Whether to override the chart's native width with the width of
|
|
727
|
+
the parent container. This can be one of the following:
|
|
697
728
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
Streamlit sets the width of the chart to
|
|
702
|
-
|
|
703
|
-
|
|
729
|
+
- ``None`` (default): Streamlit will use the chart's default behavior.
|
|
730
|
+
- ``True``: Streamlit sets the width of the chart to match the
|
|
731
|
+
width of the parent container.
|
|
732
|
+
- ``False``: Streamlit sets the width of the chart to fit its
|
|
733
|
+
contents according to the plotting library, up to the width of
|
|
734
|
+
the parent container.
|
|
735
|
+
|
|
736
|
+
.. deprecated::
|
|
737
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
738
|
+
future release. For ``use_container_width=True``, use
|
|
739
|
+
``width="stretch"``.
|
|
704
740
|
|
|
705
741
|
Examples
|
|
706
742
|
--------
|
|
@@ -777,7 +813,6 @@ class VegaChartsMixin:
|
|
|
777
813
|
height: 440px
|
|
778
814
|
|
|
779
815
|
"""
|
|
780
|
-
|
|
781
816
|
chart, add_rows_metadata = generate_chart(
|
|
782
817
|
chart_type=ChartType.LINE,
|
|
783
818
|
data=data,
|
|
@@ -789,8 +824,9 @@ class VegaChartsMixin:
|
|
|
789
824
|
size_from_user=None,
|
|
790
825
|
width=width,
|
|
791
826
|
height=height,
|
|
792
|
-
use_container_width=
|
|
827
|
+
use_container_width=(width == "stretch"),
|
|
793
828
|
)
|
|
829
|
+
|
|
794
830
|
return cast(
|
|
795
831
|
"DeltaGenerator",
|
|
796
832
|
self._altair_chart(
|
|
@@ -798,6 +834,8 @@ class VegaChartsMixin:
|
|
|
798
834
|
use_container_width=use_container_width,
|
|
799
835
|
theme="streamlit",
|
|
800
836
|
add_rows_metadata=add_rows_metadata,
|
|
837
|
+
width=width,
|
|
838
|
+
height=height,
|
|
801
839
|
),
|
|
802
840
|
)
|
|
803
841
|
|
|
@@ -812,9 +850,9 @@ class VegaChartsMixin:
|
|
|
812
850
|
y_label: str | None = None,
|
|
813
851
|
color: str | Color | list[Color] | None = None,
|
|
814
852
|
stack: bool | ChartStackType | None = None,
|
|
815
|
-
width:
|
|
816
|
-
height:
|
|
817
|
-
use_container_width: bool =
|
|
853
|
+
width: Width = "stretch",
|
|
854
|
+
height: Height = "content",
|
|
855
|
+
use_container_width: bool | None = None,
|
|
818
856
|
) -> DeltaGenerator:
|
|
819
857
|
"""Display an area chart.
|
|
820
858
|
|
|
@@ -823,9 +861,6 @@ class VegaChartsMixin:
|
|
|
823
861
|
the chart's Altair spec. As a result this is easier to use for many
|
|
824
862
|
"just plot this" scenarios, while being less customizable.
|
|
825
863
|
|
|
826
|
-
If ``st.area_chart`` does not guess the data specification
|
|
827
|
-
correctly, try specifying your desired chart using ``st.altair_chart``.
|
|
828
|
-
|
|
829
864
|
Parameters
|
|
830
865
|
----------
|
|
831
866
|
data : Anything supported by st.dataframe
|
|
@@ -908,27 +943,46 @@ class VegaChartsMixin:
|
|
|
908
943
|
- ``"center"``: The areas are stacked and shifted to center their
|
|
909
944
|
baseline, which creates a steamgraph.
|
|
910
945
|
|
|
911
|
-
width :
|
|
912
|
-
|
|
913
|
-
``None`` (default), Streamlit sets the width of the chart to fit
|
|
914
|
-
its contents according to the plotting library, up to the width of
|
|
915
|
-
the parent container. If ``width`` is greater than the width of the
|
|
916
|
-
parent container, Streamlit sets the chart width to match the width
|
|
917
|
-
of the parent container.
|
|
946
|
+
width : "stretch", "content", or int
|
|
947
|
+
The width of the chart element. This can be one of the following:
|
|
918
948
|
|
|
919
|
-
|
|
949
|
+
- ``"stretch"`` (default): The width of the element matches the
|
|
950
|
+
width of the parent container.
|
|
951
|
+
- ``"content"``: The width of the element matches the width of its
|
|
952
|
+
content, but doesn't exceed the width of the parent container.
|
|
953
|
+
- An integer specifying the width in pixels: The element has a
|
|
954
|
+
fixed width. If the specified width is greater than the width of
|
|
955
|
+
the parent container, the width of the element matches the width
|
|
956
|
+
of the parent container.
|
|
957
|
+
|
|
958
|
+
height : "stretch", "content", or int
|
|
959
|
+
The height of the chart element. This can be one of the following:
|
|
960
|
+
|
|
961
|
+
- ``"content"`` (default): The height of the element matches the
|
|
962
|
+
height of its content.
|
|
963
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
964
|
+
its content or the height of the parent container, whichever is
|
|
965
|
+
larger. If the element is not in a parent container, the height
|
|
966
|
+
of the element matches the height of its content.
|
|
967
|
+
- An integer specifying the height in pixels: The element has a
|
|
968
|
+
fixed height. If the content is larger than the specified
|
|
969
|
+
height, scrolling is enabled.
|
|
920
970
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
its contents according to the plotting library.
|
|
971
|
+
use_container_width : bool or None
|
|
972
|
+
Whether to override the chart's native width with the width of
|
|
973
|
+
the parent container. This can be one of the following:
|
|
925
974
|
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
Streamlit sets the width of the chart to
|
|
930
|
-
|
|
931
|
-
|
|
975
|
+
- ``None`` (default): Streamlit will use the chart's default behavior.
|
|
976
|
+
- ``True``: Streamlit sets the width of the chart to match the
|
|
977
|
+
width of the parent container.
|
|
978
|
+
- ``False``: Streamlit sets the width of the chart to fit its
|
|
979
|
+
contents according to the plotting library, up to the width of
|
|
980
|
+
the parent container.
|
|
981
|
+
|
|
982
|
+
.. deprecated::
|
|
983
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
984
|
+
future release. For ``use_container_width=True``, use
|
|
985
|
+
``width="stretch"``.
|
|
932
986
|
|
|
933
987
|
Examples
|
|
934
988
|
--------
|
|
@@ -1029,7 +1083,6 @@ class VegaChartsMixin:
|
|
|
1029
1083
|
height: 440px
|
|
1030
1084
|
|
|
1031
1085
|
"""
|
|
1032
|
-
|
|
1033
1086
|
# Check that the stack parameter is valid, raise more informative error message if not
|
|
1034
1087
|
maybe_raise_stack_warning(
|
|
1035
1088
|
stack,
|
|
@@ -1059,7 +1112,7 @@ class VegaChartsMixin:
|
|
|
1059
1112
|
width=width,
|
|
1060
1113
|
height=height,
|
|
1061
1114
|
stack=stack,
|
|
1062
|
-
use_container_width=
|
|
1115
|
+
use_container_width=(width == "stretch"),
|
|
1063
1116
|
)
|
|
1064
1117
|
return cast(
|
|
1065
1118
|
"DeltaGenerator",
|
|
@@ -1068,6 +1121,8 @@ class VegaChartsMixin:
|
|
|
1068
1121
|
use_container_width=use_container_width,
|
|
1069
1122
|
theme="streamlit",
|
|
1070
1123
|
add_rows_metadata=add_rows_metadata,
|
|
1124
|
+
width=width,
|
|
1125
|
+
height=height,
|
|
1071
1126
|
),
|
|
1072
1127
|
)
|
|
1073
1128
|
|
|
@@ -1082,10 +1137,11 @@ class VegaChartsMixin:
|
|
|
1082
1137
|
y_label: str | None = None,
|
|
1083
1138
|
color: str | Color | list[Color] | None = None,
|
|
1084
1139
|
horizontal: bool = False,
|
|
1140
|
+
sort: bool | str = True,
|
|
1085
1141
|
stack: bool | ChartStackType | None = None,
|
|
1086
|
-
width:
|
|
1087
|
-
height:
|
|
1088
|
-
use_container_width: bool =
|
|
1142
|
+
width: Width = "stretch",
|
|
1143
|
+
height: Height = "content",
|
|
1144
|
+
use_container_width: bool | None = None,
|
|
1089
1145
|
) -> DeltaGenerator:
|
|
1090
1146
|
"""Display a bar chart.
|
|
1091
1147
|
|
|
@@ -1094,9 +1150,6 @@ class VegaChartsMixin:
|
|
|
1094
1150
|
the chart's Altair spec. As a result this is easier to use for many
|
|
1095
1151
|
"just plot this" scenarios, while being less customizable.
|
|
1096
1152
|
|
|
1097
|
-
If ``st.bar_chart`` does not guess the data specification
|
|
1098
|
-
correctly, try specifying your desired chart using ``st.altair_chart``.
|
|
1099
|
-
|
|
1100
1153
|
Parameters
|
|
1101
1154
|
----------
|
|
1102
1155
|
data : Anything supported by st.dataframe
|
|
@@ -1173,6 +1226,19 @@ class VegaChartsMixin:
|
|
|
1173
1226
|
Streamlit swaps the x-axis and y-axis and the bars display
|
|
1174
1227
|
horizontally.
|
|
1175
1228
|
|
|
1229
|
+
sort : bool or str
|
|
1230
|
+
How to sort the bars. This can be one of the following:
|
|
1231
|
+
|
|
1232
|
+
- ``True`` (default): The bars are sorted automatically along the
|
|
1233
|
+
independent/categorical axis with Altair's default sorting. This
|
|
1234
|
+
also correctly sorts ordered categorical columns
|
|
1235
|
+
(``pd.Categorical``).
|
|
1236
|
+
- ``False``: The bars are shown in data order without sorting.
|
|
1237
|
+
- The name of a column (e.g. ``"col1"``): The bars are sorted by
|
|
1238
|
+
that column in ascending order.
|
|
1239
|
+
- The name of a column with a minus-sign prefix (e.g. ``"-col1"``):
|
|
1240
|
+
The bars are sorted by that column in descending order.
|
|
1241
|
+
|
|
1176
1242
|
stack : bool, "normalize", "center", "layered", or None
|
|
1177
1243
|
Whether to stack the bars. If this is ``None`` (default),
|
|
1178
1244
|
Streamlit uses Vega's default. Other values can be as follows:
|
|
@@ -1186,27 +1252,46 @@ class VegaChartsMixin:
|
|
|
1186
1252
|
- ``"center"``: The bars are stacked and shifted to center the
|
|
1187
1253
|
total height around an axis.
|
|
1188
1254
|
|
|
1189
|
-
width :
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1255
|
+
width : "stretch", "content", or int
|
|
1256
|
+
The width of the chart element. This can be one of the following:
|
|
1257
|
+
|
|
1258
|
+
- ``"stretch"`` (default): The width of the element matches the
|
|
1259
|
+
width of the parent container.
|
|
1260
|
+
- ``"content"``: The width of the element matches the width of its
|
|
1261
|
+
content, but doesn't exceed the width of the parent container.
|
|
1262
|
+
- An integer specifying the width in pixels: The element has a
|
|
1263
|
+
fixed width. If the specified width is greater than the width of
|
|
1264
|
+
the parent container, the width of the element matches the width
|
|
1265
|
+
of the parent container.
|
|
1266
|
+
|
|
1267
|
+
height : "stretch", "content", or int
|
|
1268
|
+
The height of the chart element. This can be one of the following:
|
|
1269
|
+
|
|
1270
|
+
- ``"content"`` (default): The height of the element matches the
|
|
1271
|
+
height of its content.
|
|
1272
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
1273
|
+
its content or the height of the parent container, whichever is
|
|
1274
|
+
larger. If the element is not in a parent container, the height
|
|
1275
|
+
of the element matches the height of its content.
|
|
1276
|
+
- An integer specifying the height in pixels: The element has a
|
|
1277
|
+
fixed height. If the content is larger than the specified
|
|
1278
|
+
height, scrolling is enabled.
|
|
1196
1279
|
|
|
1197
|
-
|
|
1280
|
+
use_container_width : bool or None
|
|
1281
|
+
Whether to override the chart's native width with the width of
|
|
1282
|
+
the parent container. This can be one of the following:
|
|
1198
1283
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1284
|
+
- ``None`` (default): Streamlit will use the chart's default behavior.
|
|
1285
|
+
- ``True``: Streamlit sets the width of the chart to match the
|
|
1286
|
+
width of the parent container.
|
|
1287
|
+
- ``False``: Streamlit sets the width of the chart to fit its
|
|
1288
|
+
contents according to the plotting library, up to the width of
|
|
1289
|
+
the parent container.
|
|
1203
1290
|
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
parent container. If ``use_container_width`` is ``False``,
|
|
1209
|
-
Streamlit sets the chart's width according to ``width``.
|
|
1291
|
+
.. deprecated::
|
|
1292
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
1293
|
+
future release. For ``use_container_width=True``, use
|
|
1294
|
+
``width="stretch"``.
|
|
1210
1295
|
|
|
1211
1296
|
Examples
|
|
1212
1297
|
--------
|
|
@@ -1324,7 +1409,6 @@ class VegaChartsMixin:
|
|
|
1324
1409
|
height: 440px
|
|
1325
1410
|
|
|
1326
1411
|
"""
|
|
1327
|
-
|
|
1328
1412
|
# Check that the stack parameter is valid, raise more informative error message if not
|
|
1329
1413
|
maybe_raise_stack_warning(
|
|
1330
1414
|
stack,
|
|
@@ -1357,6 +1441,7 @@ class VegaChartsMixin:
|
|
|
1357
1441
|
use_container_width=use_container_width,
|
|
1358
1442
|
stack=stack,
|
|
1359
1443
|
horizontal=horizontal,
|
|
1444
|
+
sort_from_user=sort,
|
|
1360
1445
|
)
|
|
1361
1446
|
return cast(
|
|
1362
1447
|
"DeltaGenerator",
|
|
@@ -1365,6 +1450,8 @@ class VegaChartsMixin:
|
|
|
1365
1450
|
use_container_width=use_container_width,
|
|
1366
1451
|
theme="streamlit",
|
|
1367
1452
|
add_rows_metadata=add_rows_metadata,
|
|
1453
|
+
width=width,
|
|
1454
|
+
height=height,
|
|
1368
1455
|
),
|
|
1369
1456
|
)
|
|
1370
1457
|
|
|
@@ -1379,9 +1466,9 @@ class VegaChartsMixin:
|
|
|
1379
1466
|
y_label: str | None = None,
|
|
1380
1467
|
color: str | Color | list[Color] | None = None,
|
|
1381
1468
|
size: str | float | int | None = None,
|
|
1382
|
-
width:
|
|
1383
|
-
height:
|
|
1384
|
-
use_container_width: bool =
|
|
1469
|
+
width: Width = "stretch",
|
|
1470
|
+
height: Height = "content",
|
|
1471
|
+
use_container_width: bool | None = None,
|
|
1385
1472
|
) -> DeltaGenerator:
|
|
1386
1473
|
"""Display a scatterplot chart.
|
|
1387
1474
|
|
|
@@ -1390,9 +1477,6 @@ class VegaChartsMixin:
|
|
|
1390
1477
|
the chart's Altair spec. As a result this is easier to use for many
|
|
1391
1478
|
"just plot this" scenarios, while being less customizable.
|
|
1392
1479
|
|
|
1393
|
-
If ``st.scatter_chart`` does not guess the data specification correctly,
|
|
1394
|
-
try specifying your desired chart using ``st.altair_chart``.
|
|
1395
|
-
|
|
1396
1480
|
Parameters
|
|
1397
1481
|
----------
|
|
1398
1482
|
data : Anything supported by st.dataframe
|
|
@@ -1469,27 +1553,46 @@ class VegaChartsMixin:
|
|
|
1469
1553
|
- The name of the column to use for the size. This allows each
|
|
1470
1554
|
datapoint to be represented by a circle of a different size.
|
|
1471
1555
|
|
|
1472
|
-
width :
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1556
|
+
width : "stretch", "content", or int
|
|
1557
|
+
The width of the chart element. This can be one of the following:
|
|
1558
|
+
|
|
1559
|
+
- ``"stretch"`` (default): The width of the element matches the
|
|
1560
|
+
width of the parent container.
|
|
1561
|
+
- ``"content"``: The width of the element matches the width of its
|
|
1562
|
+
content, but doesn't exceed the width of the parent container.
|
|
1563
|
+
- An integer specifying the width in pixels: The element has a
|
|
1564
|
+
fixed width. If the specified width is greater than the width of
|
|
1565
|
+
the parent container, the width of the element matches the width
|
|
1566
|
+
of the parent container.
|
|
1567
|
+
|
|
1568
|
+
height : "stretch", "content", or int
|
|
1569
|
+
The height of the chart element. This can be one of the following:
|
|
1570
|
+
|
|
1571
|
+
- ``"content"`` (default): The height of the element matches the
|
|
1572
|
+
height of its content.
|
|
1573
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
1574
|
+
its content or the height of the parent container, whichever is
|
|
1575
|
+
larger. If the element is not in a parent container, the height
|
|
1576
|
+
of the element matches the height of its content.
|
|
1577
|
+
- An integer specifying the height in pixels: The element has a
|
|
1578
|
+
fixed height. If the content is larger than the specified
|
|
1579
|
+
height, scrolling is enabled.
|
|
1479
1580
|
|
|
1480
|
-
|
|
1581
|
+
use_container_width : bool or None
|
|
1582
|
+
Whether to override the chart's native width with the width of
|
|
1583
|
+
the parent container. This can be one of the following:
|
|
1481
1584
|
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1585
|
+
- ``None`` (default): Streamlit will use the chart's default behavior.
|
|
1586
|
+
- ``True``: Streamlit sets the width of the chart to match the
|
|
1587
|
+
width of the parent container.
|
|
1588
|
+
- ``False``: Streamlit sets the width of the chart to fit its
|
|
1589
|
+
contents according to the plotting library, up to the width of
|
|
1590
|
+
the parent container.
|
|
1486
1591
|
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
parent container. If ``use_container_width`` is ``False``,
|
|
1492
|
-
Streamlit sets the chart's width according to ``width``.
|
|
1592
|
+
.. deprecated::
|
|
1593
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
1594
|
+
future release. For ``use_container_width=True``, use
|
|
1595
|
+
``width="stretch"``.
|
|
1493
1596
|
|
|
1494
1597
|
Examples
|
|
1495
1598
|
--------
|
|
@@ -1574,7 +1677,6 @@ class VegaChartsMixin:
|
|
|
1574
1677
|
height: 440px
|
|
1575
1678
|
|
|
1576
1679
|
"""
|
|
1577
|
-
|
|
1578
1680
|
chart, add_rows_metadata = generate_chart(
|
|
1579
1681
|
chart_type=ChartType.SCATTER,
|
|
1580
1682
|
data=data,
|
|
@@ -1586,7 +1688,7 @@ class VegaChartsMixin:
|
|
|
1586
1688
|
size_from_user=size,
|
|
1587
1689
|
width=width,
|
|
1588
1690
|
height=height,
|
|
1589
|
-
use_container_width=
|
|
1691
|
+
use_container_width=(width == "stretch"),
|
|
1590
1692
|
)
|
|
1591
1693
|
return cast(
|
|
1592
1694
|
"DeltaGenerator",
|
|
@@ -1595,6 +1697,8 @@ class VegaChartsMixin:
|
|
|
1595
1697
|
use_container_width=use_container_width,
|
|
1596
1698
|
theme="streamlit",
|
|
1597
1699
|
add_rows_metadata=add_rows_metadata,
|
|
1700
|
+
width=width,
|
|
1701
|
+
height=height,
|
|
1598
1702
|
),
|
|
1599
1703
|
)
|
|
1600
1704
|
|
|
@@ -1604,6 +1708,8 @@ class VegaChartsMixin:
|
|
|
1604
1708
|
self,
|
|
1605
1709
|
altair_chart: AltairChart,
|
|
1606
1710
|
*,
|
|
1711
|
+
width: Width | None = None,
|
|
1712
|
+
height: Height = "content",
|
|
1607
1713
|
use_container_width: bool | None = None,
|
|
1608
1714
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1609
1715
|
key: Key | None = None,
|
|
@@ -1617,6 +1723,8 @@ class VegaChartsMixin:
|
|
|
1617
1723
|
self,
|
|
1618
1724
|
altair_chart: AltairChart,
|
|
1619
1725
|
*,
|
|
1726
|
+
width: Width | None = None,
|
|
1727
|
+
height: Height = "content",
|
|
1620
1728
|
use_container_width: bool | None = None,
|
|
1621
1729
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1622
1730
|
key: Key | None = None,
|
|
@@ -1629,6 +1737,8 @@ class VegaChartsMixin:
|
|
|
1629
1737
|
self,
|
|
1630
1738
|
altair_chart: AltairChart,
|
|
1631
1739
|
*,
|
|
1740
|
+
width: Width | None = None,
|
|
1741
|
+
height: Height = "content",
|
|
1632
1742
|
use_container_width: bool | None = None,
|
|
1633
1743
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1634
1744
|
key: Key | None = None,
|
|
@@ -1648,6 +1758,39 @@ class VegaChartsMixin:
|
|
|
1648
1758
|
https://altair-viz.github.io/gallery/ for examples of graph
|
|
1649
1759
|
descriptions.
|
|
1650
1760
|
|
|
1761
|
+
width : "stretch", "content", int, or None
|
|
1762
|
+
The width of the chart element. This can be one of the following:
|
|
1763
|
+
|
|
1764
|
+
- ``"stretch"``: The width of the element matches the width of the
|
|
1765
|
+
parent container.
|
|
1766
|
+
- ``"content"``: The width of the element matches the width of its
|
|
1767
|
+
content, but doesn't exceed the width of the parent container.
|
|
1768
|
+
- An integer specifying the width in pixels: The element has a
|
|
1769
|
+
fixed width. If the specified width is greater than the width of
|
|
1770
|
+
the parent container, the width of the element matches the width
|
|
1771
|
+
of the parent container.
|
|
1772
|
+
- ``None`` (default): Streamlit uses ``"stretch"`` for most charts,
|
|
1773
|
+
and uses ``"content"`` for the following multi-view charts:
|
|
1774
|
+
|
|
1775
|
+
- Facet charts: the spec contains ``"facet"`` or encodings for
|
|
1776
|
+
``"row"``, ``"column"``, or ``"facet"``.
|
|
1777
|
+
- Horizontal concatenation charts: the spec contains
|
|
1778
|
+
``"hconcat"``.
|
|
1779
|
+
- Repeat charts: the spec contains ``"repeat"``.
|
|
1780
|
+
|
|
1781
|
+
height : "content", "stretch", or int
|
|
1782
|
+
The height of the chart element. This can be one of the following:
|
|
1783
|
+
|
|
1784
|
+
- ``"content"`` (default): The height of the element matches the
|
|
1785
|
+
height of its content.
|
|
1786
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
1787
|
+
its content or the height of the parent container, whichever is
|
|
1788
|
+
larger. If the element is not in a parent container, the height
|
|
1789
|
+
of the element matches the height of its content.
|
|
1790
|
+
- An integer specifying the height in pixels: The element has a
|
|
1791
|
+
fixed height. If the content is larger than the specified
|
|
1792
|
+
height, scrolling is enabled.
|
|
1793
|
+
|
|
1651
1794
|
use_container_width : bool or None
|
|
1652
1795
|
Whether to override the chart's native width with the width of
|
|
1653
1796
|
the parent container. This can be one of the following:
|
|
@@ -1662,6 +1805,11 @@ class VegaChartsMixin:
|
|
|
1662
1805
|
contents according to the plotting library, up to the width of
|
|
1663
1806
|
the parent container.
|
|
1664
1807
|
|
|
1808
|
+
.. deprecated::
|
|
1809
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
1810
|
+
future release. For ``use_container_width=True``, use
|
|
1811
|
+
``width="stretch"``.
|
|
1812
|
+
|
|
1665
1813
|
theme : "streamlit" or None
|
|
1666
1814
|
The theme of the chart. If ``theme`` is ``"streamlit"`` (default),
|
|
1667
1815
|
Streamlit uses its own design default. If ``theme`` is ``None``,
|
|
@@ -1754,6 +1902,8 @@ class VegaChartsMixin:
|
|
|
1754
1902
|
"""
|
|
1755
1903
|
return self._altair_chart(
|
|
1756
1904
|
altair_chart=altair_chart,
|
|
1905
|
+
width=width,
|
|
1906
|
+
height=height,
|
|
1757
1907
|
use_container_width=use_container_width,
|
|
1758
1908
|
theme=theme,
|
|
1759
1909
|
key=key,
|
|
@@ -1768,6 +1918,8 @@ class VegaChartsMixin:
|
|
|
1768
1918
|
data: Data = None,
|
|
1769
1919
|
spec: VegaLiteSpec | None = None,
|
|
1770
1920
|
*,
|
|
1921
|
+
width: Width | None = None,
|
|
1922
|
+
height: Height = "content",
|
|
1771
1923
|
use_container_width: bool | None = None,
|
|
1772
1924
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1773
1925
|
key: Key | None = None,
|
|
@@ -1783,6 +1935,8 @@ class VegaChartsMixin:
|
|
|
1783
1935
|
data: Data = None,
|
|
1784
1936
|
spec: VegaLiteSpec | None = None,
|
|
1785
1937
|
*,
|
|
1938
|
+
width: Width | None = None,
|
|
1939
|
+
height: Height = "content",
|
|
1786
1940
|
use_container_width: bool | None = None,
|
|
1787
1941
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1788
1942
|
key: Key | None = None,
|
|
@@ -1797,6 +1951,8 @@ class VegaChartsMixin:
|
|
|
1797
1951
|
data: Data = None,
|
|
1798
1952
|
spec: VegaLiteSpec | None = None,
|
|
1799
1953
|
*,
|
|
1954
|
+
width: Width | None = None,
|
|
1955
|
+
height: Height = "content",
|
|
1800
1956
|
use_container_width: bool | None = None,
|
|
1801
1957
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1802
1958
|
key: Key | None = None,
|
|
@@ -1821,6 +1977,39 @@ class VegaChartsMixin:
|
|
|
1821
1977
|
to both ``data`` and ``spec``. See
|
|
1822
1978
|
https://vega.github.io/vega-lite/docs/ for more info.
|
|
1823
1979
|
|
|
1980
|
+
width : "stretch", "content", int, or None
|
|
1981
|
+
The width of the chart element. This can be one of the following:
|
|
1982
|
+
|
|
1983
|
+
- ``"stretch"``: The width of the element matches the width of the
|
|
1984
|
+
parent container.
|
|
1985
|
+
- ``"content"``: The width of the element matches the width of its
|
|
1986
|
+
content, but doesn't exceed the width of the parent container.
|
|
1987
|
+
- An integer specifying the width in pixels: The element has a
|
|
1988
|
+
fixed width. If the specified width is greater than the width of
|
|
1989
|
+
the parent container, the width of the element matches the width
|
|
1990
|
+
of the parent container.
|
|
1991
|
+
- ``None`` (default): Streamlit uses ``"stretch"`` for most charts,
|
|
1992
|
+
and uses ``"content"`` for the following multi-view charts:
|
|
1993
|
+
|
|
1994
|
+
- Facet charts: the spec contains ``"facet"`` or encodings for
|
|
1995
|
+
``"row"``, ``"column"``, or ``"facet"``.
|
|
1996
|
+
- Horizontal concatenation charts: the spec contains
|
|
1997
|
+
``"hconcat"``.
|
|
1998
|
+
- Repeat charts: the spec contains ``"repeat"``.
|
|
1999
|
+
|
|
2000
|
+
height : "content", "stretch", or int
|
|
2001
|
+
The height of the chart element. This can be one of the following:
|
|
2002
|
+
|
|
2003
|
+
- ``"content"`` (default): The height of the element matches the
|
|
2004
|
+
height of its content.
|
|
2005
|
+
- ``"stretch"``: The height of the element matches the height of
|
|
2006
|
+
its content or the height of the parent container, whichever is
|
|
2007
|
+
larger. If the element is not in a parent container, the height
|
|
2008
|
+
of the element matches the height of its content.
|
|
2009
|
+
- An integer specifying the height in pixels: The element has a
|
|
2010
|
+
fixed height. If the content is larger than the specified
|
|
2011
|
+
height, scrolling is enabled.
|
|
2012
|
+
|
|
1824
2013
|
use_container_width : bool or None
|
|
1825
2014
|
Whether to override the chart's native width with the width of
|
|
1826
2015
|
the parent container. This can be one of the following:
|
|
@@ -1835,6 +2024,11 @@ class VegaChartsMixin:
|
|
|
1835
2024
|
contents according to the plotting library, up to the width of
|
|
1836
2025
|
the parent container.
|
|
1837
2026
|
|
|
2027
|
+
.. deprecated::
|
|
2028
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
2029
|
+
future release. For ``use_container_width=True``, use
|
|
2030
|
+
``width="stretch"``.
|
|
2031
|
+
|
|
1838
2032
|
theme : "streamlit" or None
|
|
1839
2033
|
The theme of the chart. If ``theme`` is ``"streamlit"`` (default),
|
|
1840
2034
|
Streamlit uses its own design default. If ``theme`` is ``None``,
|
|
@@ -1944,6 +2138,8 @@ class VegaChartsMixin:
|
|
|
1944
2138
|
key=key,
|
|
1945
2139
|
on_select=on_select,
|
|
1946
2140
|
selection_mode=selection_mode,
|
|
2141
|
+
width=width,
|
|
2142
|
+
height=height,
|
|
1947
2143
|
**kwargs,
|
|
1948
2144
|
)
|
|
1949
2145
|
|
|
@@ -1956,6 +2152,8 @@ class VegaChartsMixin:
|
|
|
1956
2152
|
on_select: Literal["rerun", "ignore"] | WidgetCallback = "ignore",
|
|
1957
2153
|
selection_mode: str | Iterable[str] | None = None,
|
|
1958
2154
|
add_rows_metadata: AddRowsMetadata | None = None,
|
|
2155
|
+
width: Width | None = None,
|
|
2156
|
+
height: Height = "content",
|
|
1959
2157
|
) -> DeltaGenerator | VegaLiteState:
|
|
1960
2158
|
"""Internal method to enqueue a vega-lite chart element based on an Altair chart.
|
|
1961
2159
|
|
|
@@ -1980,6 +2178,8 @@ class VegaChartsMixin:
|
|
|
1980
2178
|
on_select=on_select,
|
|
1981
2179
|
selection_mode=selection_mode,
|
|
1982
2180
|
add_rows_metadata=add_rows_metadata,
|
|
2181
|
+
width=width,
|
|
2182
|
+
height=height,
|
|
1983
2183
|
)
|
|
1984
2184
|
|
|
1985
2185
|
def _vega_lite_chart(
|
|
@@ -1992,13 +2192,14 @@ class VegaChartsMixin:
|
|
|
1992
2192
|
on_select: Literal["rerun", "ignore"] | WidgetCallback = "ignore",
|
|
1993
2193
|
selection_mode: str | Iterable[str] | None = None,
|
|
1994
2194
|
add_rows_metadata: AddRowsMetadata | None = None,
|
|
2195
|
+
width: Width | None = None,
|
|
2196
|
+
height: Height = "content",
|
|
1995
2197
|
**kwargs: Any,
|
|
1996
2198
|
) -> DeltaGenerator | VegaLiteState:
|
|
1997
2199
|
"""Internal method to enqueue a vega-lite chart element based on a vega-lite spec.
|
|
1998
2200
|
|
|
1999
2201
|
See the `vega_lite_chart` method docstring for more information.
|
|
2000
2202
|
"""
|
|
2001
|
-
|
|
2002
2203
|
if theme not in ["streamlit", None]:
|
|
2003
2204
|
raise StreamlitAPIException(
|
|
2004
2205
|
f'You set theme="{theme}" while Streamlit charts only support '
|
|
@@ -2037,30 +2238,64 @@ class VegaChartsMixin:
|
|
|
2037
2238
|
if spec is None:
|
|
2038
2239
|
spec = {}
|
|
2039
2240
|
|
|
2040
|
-
# Set the default value for
|
|
2041
|
-
|
|
2241
|
+
# Set the default value for width. Altair and Vega charts have different defaults depending on the chart type,
|
|
2242
|
+
# so they don't default the value in the function signature and width could be None here.
|
|
2243
|
+
if use_container_width is None and width is None:
|
|
2042
2244
|
# Some multi-view charts (facet, horizontal concatenation, and repeat;
|
|
2043
2245
|
# see https://altair-viz.github.io/user_guide/compound_charts.html)
|
|
2044
|
-
# don't work well with `
|
|
2246
|
+
# don't work well with `width=stretch`, so we disable it for
|
|
2045
2247
|
# those charts (see https://github.com/streamlit/streamlit/issues/9091).
|
|
2046
2248
|
# All other charts (including vertical concatenation) default to
|
|
2047
|
-
# `
|
|
2249
|
+
# `width=stretch` unless width is provided.
|
|
2048
2250
|
is_facet_chart = "facet" in spec or (
|
|
2049
2251
|
"encoding" in spec
|
|
2050
2252
|
and (any(x in spec["encoding"] for x in ["row", "column", "facet"]))
|
|
2051
2253
|
)
|
|
2052
|
-
|
|
2053
|
-
|
|
2254
|
+
width = (
|
|
2255
|
+
"stretch"
|
|
2256
|
+
if not (is_facet_chart or "hconcat" in spec or "repeat" in spec)
|
|
2257
|
+
else "content"
|
|
2258
|
+
)
|
|
2259
|
+
|
|
2260
|
+
if use_container_width is not None:
|
|
2261
|
+
show_deprecation_warning(
|
|
2262
|
+
make_deprecated_name_warning(
|
|
2263
|
+
"use_container_width",
|
|
2264
|
+
"width",
|
|
2265
|
+
"2025-12-31",
|
|
2266
|
+
"For `use_container_width=True`, use `width='stretch'`. "
|
|
2267
|
+
"For `use_container_width=False`, use `width='content'` or specify an integer width.",
|
|
2268
|
+
include_st_prefix=False,
|
|
2269
|
+
),
|
|
2270
|
+
show_in_browser=False,
|
|
2054
2271
|
)
|
|
2272
|
+
if use_container_width:
|
|
2273
|
+
width = "stretch"
|
|
2274
|
+
elif not isinstance(width, int):
|
|
2275
|
+
# No specific width provided, use content width
|
|
2276
|
+
width = "content"
|
|
2277
|
+
# Otherwise keep the integer width - user explicitly set both use_container_width=False and width=int
|
|
2278
|
+
|
|
2279
|
+
if width is not None:
|
|
2280
|
+
validate_width(width, allow_content=True)
|
|
2281
|
+
validate_height(height, allow_content=True)
|
|
2055
2282
|
|
|
2056
2283
|
vega_lite_proto = ArrowVegaLiteChartProto()
|
|
2057
2284
|
|
|
2058
|
-
|
|
2285
|
+
use_container_width_for_spec = (
|
|
2286
|
+
use_container_width
|
|
2287
|
+
if use_container_width is not None
|
|
2288
|
+
else width == "stretch"
|
|
2289
|
+
)
|
|
2290
|
+
|
|
2291
|
+
spec = _prepare_vega_lite_spec(spec, use_container_width_for_spec, **kwargs)
|
|
2059
2292
|
_marshall_chart_data(vega_lite_proto, spec, data)
|
|
2060
2293
|
|
|
2061
2294
|
# Prevent the spec from changing across reruns:
|
|
2062
2295
|
vega_lite_proto.spec = _stabilize_vega_json_spec(json.dumps(spec))
|
|
2063
|
-
|
|
2296
|
+
|
|
2297
|
+
if use_container_width is not None:
|
|
2298
|
+
vega_lite_proto.use_container_width = use_container_width
|
|
2064
2299
|
vega_lite_proto.theme = theme or ""
|
|
2065
2300
|
|
|
2066
2301
|
if is_selection_activated:
|
|
@@ -2079,6 +2314,7 @@ class VegaChartsMixin:
|
|
|
2079
2314
|
vega_lite_proto.id = compute_and_register_element_id(
|
|
2080
2315
|
"arrow_vega_lite_chart",
|
|
2081
2316
|
user_key=key,
|
|
2317
|
+
key_as_main_identity=False,
|
|
2082
2318
|
dg=self.dg,
|
|
2083
2319
|
vega_lite_spec=vega_lite_proto.spec,
|
|
2084
2320
|
# The data is either in vega_lite_proto.data.data
|
|
@@ -2103,21 +2339,42 @@ class VegaChartsMixin:
|
|
|
2103
2339
|
value_type="string_value",
|
|
2104
2340
|
)
|
|
2105
2341
|
|
|
2342
|
+
layout_config = LayoutConfig(width=width, height=height)
|
|
2106
2343
|
self.dg._enqueue(
|
|
2107
2344
|
"arrow_vega_lite_chart",
|
|
2108
2345
|
vega_lite_proto,
|
|
2109
2346
|
add_rows_metadata=add_rows_metadata,
|
|
2347
|
+
layout_config=layout_config,
|
|
2110
2348
|
)
|
|
2111
2349
|
return widget_state.value
|
|
2350
|
+
|
|
2112
2351
|
# If its not used with selections activated, just return
|
|
2113
2352
|
# the delta generator related to this element.
|
|
2353
|
+
layout_config = LayoutConfig(width=width, height=height)
|
|
2114
2354
|
return self.dg._enqueue(
|
|
2115
2355
|
"arrow_vega_lite_chart",
|
|
2116
2356
|
vega_lite_proto,
|
|
2117
2357
|
add_rows_metadata=add_rows_metadata,
|
|
2358
|
+
layout_config=layout_config,
|
|
2118
2359
|
)
|
|
2119
2360
|
|
|
2120
2361
|
@property
|
|
2121
2362
|
def dg(self) -> DeltaGenerator:
|
|
2122
2363
|
"""Get our DeltaGenerator."""
|
|
2123
2364
|
return cast("DeltaGenerator", self)
|
|
2365
|
+
|
|
2366
|
+
|
|
2367
|
+
def _to_arrow_dataset(data: Any, datasets: dict[str, Any]) -> dict[str, str]:
|
|
2368
|
+
"""Altair data transformer that serializes the data,
|
|
2369
|
+
creates a stable name based on the hash of the data,
|
|
2370
|
+
stores the bytes into the datasets mapping and
|
|
2371
|
+
returns this name to have it be used in Altair.
|
|
2372
|
+
"""
|
|
2373
|
+
# Already serialize the data to be able to create a stable
|
|
2374
|
+
# dataset name:
|
|
2375
|
+
data_bytes = dataframe_util.convert_anything_to_arrow_bytes(data)
|
|
2376
|
+
# Use the md5 hash of the data as the name:
|
|
2377
|
+
name = calc_md5(str(data_bytes))
|
|
2378
|
+
|
|
2379
|
+
datasets[name] = data_bytes
|
|
2380
|
+
return {"name": name}
|