streamlit 1.50.0__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/commands/navigation.py +4 -6
- streamlit/commands/page_config.py +4 -6
- 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 +456 -53
- streamlit/config_option.py +4 -1
- streamlit/config_util.py +650 -1
- streamlit/dataframe_util.py +15 -8
- streamlit/delta_generator.py +6 -4
- streamlit/delta_generator_singletons.py +3 -1
- streamlit/deprecation_util.py +17 -6
- streamlit/elements/arrow.py +37 -9
- streamlit/elements/deck_gl_json_chart.py +97 -39
- streamlit/elements/dialog_decorator.py +2 -1
- streamlit/elements/exception.py +3 -1
- streamlit/elements/graphviz_chart.py +1 -3
- streamlit/elements/heading.py +3 -5
- streamlit/elements/image.py +2 -4
- streamlit/elements/layouts.py +31 -11
- streamlit/elements/lib/built_in_chart_utils.py +1 -3
- streamlit/elements/lib/color_util.py +8 -18
- streamlit/elements/lib/column_config_utils.py +4 -8
- streamlit/elements/lib/column_types.py +40 -12
- streamlit/elements/lib/dialog.py +2 -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/utils.py +4 -4
- streamlit/elements/map.py +80 -37
- streamlit/elements/media.py +5 -7
- streamlit/elements/metric.py +3 -5
- streamlit/elements/pdf.py +2 -4
- streamlit/elements/plotly_chart.py +125 -17
- streamlit/elements/progress.py +2 -4
- streamlit/elements/space.py +113 -0
- streamlit/elements/vega_charts.py +339 -148
- streamlit/elements/widgets/audio_input.py +5 -5
- streamlit/elements/widgets/button.py +2 -4
- streamlit/elements/widgets/button_group.py +33 -7
- streamlit/elements/widgets/camera_input.py +2 -4
- streamlit/elements/widgets/chat.py +7 -1
- streamlit/elements/widgets/color_picker.py +1 -1
- streamlit/elements/widgets/data_editor.py +28 -24
- streamlit/elements/widgets/file_uploader.py +5 -10
- streamlit/elements/widgets/multiselect.py +4 -3
- streamlit/elements/widgets/number_input.py +2 -4
- streamlit/elements/widgets/radio.py +10 -3
- streamlit/elements/widgets/select_slider.py +8 -5
- streamlit/elements/widgets/selectbox.py +6 -3
- streamlit/elements/widgets/slider.py +38 -42
- streamlit/elements/widgets/time_widgets.py +6 -12
- streamlit/elements/write.py +27 -6
- streamlit/emojis.py +1 -1
- streamlit/errors.py +115 -0
- 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/BidiComponent_pb2.py +34 -0
- streamlit/proto/BidiComponent_pb2.pyi +153 -0
- streamlit/proto/Block_pb2.py +7 -7
- streamlit/proto/Block_pb2.pyi +4 -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 -18
- streamlit/proto/NewSession_pb2.pyi +25 -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 +27 -1
- 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/websocket_session_manager.py +3 -1
- streamlit/source_util.py +2 -2
- streamlit/static/index.html +2 -2
- streamlit/static/manifest.json +243 -226
- streamlit/static/static/css/{index.CIiu7Ygf.css → index.BpABIXK9.css} +1 -1
- streamlit/static/static/css/index.DgR7E2CV.css +1 -0
- streamlit/static/static/js/{ErrorOutline.esm.DUpR0_Ka.js → ErrorOutline.esm.YoJdlW1p.js} +1 -1
- streamlit/static/static/js/{FileDownload.esm.CN4j9-1w.js → FileDownload.esm.Ddx8VEYy.js} +1 -1
- streamlit/static/static/js/{FileHelper.CaIUKG91.js → FileHelper.90EtOmj9.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.DTcdrasw.js → FormClearHelper.BB1Km6eP.js} +1 -1
- streamlit/static/static/js/InputInstructions.jhH15PqV.js +1 -0
- streamlit/static/static/js/{Particles.CElH0XX2.js → Particles.DUsputn1.js} +1 -1
- streamlit/static/static/js/{ProgressBar.DetlP5aY.js → ProgressBar.DLY8H6nE.js} +1 -1
- streamlit/static/static/js/{Toolbar.C77ar7rq.js → Toolbar.D8nHCkuz.js} +1 -1
- streamlit/static/static/js/{base-input.BQft14La.js → base-input.CJGiNqed.js} +3 -3
- streamlit/static/static/js/{checkbox.yZOfXCeX.js → checkbox.Cpdd482O.js} +1 -1
- streamlit/static/static/js/{createSuper.Dh9w1cs8.js → createSuper.CuQIogbW.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.DcuHuCyW.js → data-grid-overlay-editor.2Ufgxc6y.js} +1 -1
- streamlit/static/static/js/{downloader.MeHtkq8r.js → downloader.CN0K7xlu.js} +1 -1
- streamlit/static/static/js/{es6.VpBPGCnM.js → es6.BJcsVXQ0.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.yMw_ARIL.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.Cnpi3o3E.js → index.BMcFsUee.js} +1 -1
- streamlit/static/static/js/{index.DKv_lNO7.js → index.BR-IdcTb.js} +1 -1
- streamlit/static/static/js/{index.FFOzOWzC.js → index.B_dWA3vd.js} +1 -1
- streamlit/static/static/js/{index.Bj9JgOEC.js → index.BgnZEMVh.js} +1 -1
- streamlit/static/static/js/{index.Bxz2yX3P.js → index.BohqXifI.js} +1 -1
- streamlit/static/static/js/{index.Dbe-Q3C-.js → index.Br5nxKNj.js} +1 -1
- streamlit/static/static/js/{index.BjCwMzj4.js → index.BrIKVbNc.js} +2 -2
- streamlit/static/static/js/index.BtWUPzle.js +1 -0
- streamlit/static/static/js/{index.CGYqqs6j.js → index.C0RLraek.js} +1 -1
- streamlit/static/static/js/{index.D2QEXQq_.js → index.CAIjskgG.js} +1 -1
- streamlit/static/static/js/{index.6xX1278W.js → index.CAj-7vWz.js} +131 -157
- streamlit/static/static/js/{index.DK7hD7_w.js → index.CMtEit2O.js} +1 -1
- streamlit/static/static/js/{index.DNLrMXgm.js → index.CkRlykEE.js} +1 -1
- streamlit/static/static/js/{index.ClELlchS.js → index.CmN3FXfI.js} +1 -1
- streamlit/static/static/js/{index.GRUzrudl.js → index.CwbFI1_-.js} +1 -1
- streamlit/static/static/js/{index.Ctn27_AE.js → index.CxIUUfab.js} +27 -27
- streamlit/static/static/js/index.D2KPNy7e.js +1 -0
- streamlit/static/static/js/{index.B0H9IXUJ.js → index.D3GPA5k4.js} +3 -3
- streamlit/static/static/js/{index.BycLveZ4.js → index.DGAh7DMq.js} +1 -1
- streamlit/static/static/js/index.DKb_NvmG.js +197 -0
- streamlit/static/static/js/{index.BPQo7BKk.js → index.DMqgUYKq.js} +1 -1
- streamlit/static/static/js/{index.CH1tqnSs.js → index.DOFlg3dS.js} +1 -1
- streamlit/static/static/js/{index.64ejlaaT.js → index.DPUXkcQL.js} +1 -1
- streamlit/static/static/js/{index.B-hiXRzw.js → index.DX1xY89g.js} +1 -1
- streamlit/static/static/js/index.DYATBCsq.js +2 -0
- streamlit/static/static/js/{index.DHh-U0dK.js → index.DaSmGJ76.js} +3 -3
- streamlit/static/static/js/{index.DuxqVQpd.js → index.Dd7bMeLP.js} +1 -1
- streamlit/static/static/js/{index.B4cAbHP6.js → index.DjmmgI5U.js} +1 -1
- streamlit/static/static/js/{index.DcPNYEUo.js → index.Dq56CyM2.js} +1 -1
- streamlit/static/static/js/{index.CiAQIz1H.js → index.DuiXaS5_.js} +1 -1
- streamlit/static/static/js/index.DvFidMLe.js +2 -0
- streamlit/static/static/js/{index.C9BdUqTi.js → index.DwkhC5Pc.js} +1 -1
- streamlit/static/static/js/{index.B4dUQfni.js → index.Q-3sFn1v.js} +1 -1
- streamlit/static/static/js/{index.CMItVsFA.js → index.QJ5QO9sJ.js} +1 -1
- streamlit/static/static/js/{index.CTBk8Vk2.js → index.VwTaeety.js} +1 -1
- streamlit/static/static/js/{index.Ck8rQ9OL.js → index.YOqQbeX8.js} +1 -1
- streamlit/static/static/js/{input.s6pjQ49A.js → input.D4MN_FzN.js} +1 -1
- streamlit/static/static/js/{memory.Cuvsdfrl.js → memory.DrZjtdGT.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.DdgVR5m3.js → number-overlay-editor.DRwAw1In.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.CqidKeei.js → possibleConstructorReturn.exeeJQEP.js} +1 -1
- streamlit/static/static/js/record.B-tDciZb.js +1 -0
- streamlit/static/static/js/{sandbox.CCQREcJx.js → sandbox.ClO3IuUr.js} +1 -1
- streamlit/static/static/js/{timepicker.mkJF97Bb.js → timepicker.DAhu-vcF.js} +1 -1
- streamlit/static/static/js/{toConsumableArray.De7I7KVR.js → toConsumableArray.DNbljYEC.js} +1 -1
- streamlit/static/static/js/{uniqueId.RI1LJdtz.js → uniqueId.oG4Gvj1v.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.CedkNjUW.js → useBasicWidgetState.D6sOH6oI.js} +1 -1
- streamlit/static/static/js/{useTextInputAutoExpand.Ca7w8dVs.js → useTextInputAutoExpand.4u3_GcuN.js} +1 -1
- streamlit/static/static/js/{useUpdateUiValue.DeXelfRH.js → useUpdateUiValue.F2R3eTeR.js} +1 -1
- streamlit/static/static/js/wavesurfer.esm.vI8Eid4k.js +73 -0
- streamlit/static/static/js/{withFullScreenWrapper.C3561XxJ.js → withFullScreenWrapper.zothJIsI.js} +1 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.C7IFxh57.woff2 +0 -0
- streamlit/string_util.py +1 -3
- 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/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 +2 -2
- streamlit/web/server/server.py +9 -0
- streamlit/web/server/server_util.py +3 -1
- streamlit/web/server/upload_file_request_handler.py +3 -1
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/METADATA +4 -5
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/RECORD +222 -194
- streamlit/static/static/css/index.CHEnSPGk.css +0 -1
- streamlit/static/static/js/Hooks.BRba_Own.js +0 -1
- streamlit/static/static/js/InputInstructions.xnSDuYeQ.js +0 -1
- streamlit/static/static/js/index.Baqa90pe.js +0 -2
- streamlit/static/static/js/index.Bm3VbPB5.js +0 -1
- streamlit/static/static/js/index.CFMf5_ez.js +0 -197
- streamlit/static/static/js/index.Cj7DSzVR.js +0 -73
- streamlit/static/static/js/index.DH71Ezyj.js +0 -1
- streamlit/static/static/js/index.DW0Grddz.js +0 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.DeCZgS-4.woff2 +0 -0
- {streamlit-1.50.0.data → streamlit-1.51.0.data}/scripts/streamlit.cmd +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/WHEEL +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/entry_points.txt +0 -0
- {streamlit-1.50.0.dist-info → streamlit-1.51.0.dist-info}/top_level.txt +0 -0
|
@@ -18,11 +18,22 @@ 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
|
-
from typing import
|
|
24
|
+
from typing import (
|
|
25
|
+
TYPE_CHECKING,
|
|
26
|
+
Any,
|
|
27
|
+
Final,
|
|
28
|
+
Literal,
|
|
29
|
+
TypeAlias,
|
|
30
|
+
TypedDict,
|
|
31
|
+
Union,
|
|
32
|
+
cast,
|
|
33
|
+
overload,
|
|
34
|
+
)
|
|
24
35
|
|
|
25
|
-
from typing_extensions import Required
|
|
36
|
+
from typing_extensions import Required
|
|
26
37
|
|
|
27
38
|
from streamlit import dataframe_util, type_util
|
|
28
39
|
from streamlit.deprecation_util import (
|
|
@@ -106,6 +117,8 @@ AltairChart: TypeAlias = Union[
|
|
|
106
117
|
"alt.VConcatChart",
|
|
107
118
|
]
|
|
108
119
|
|
|
120
|
+
_altair_globals_lock = threading.Lock()
|
|
121
|
+
|
|
109
122
|
|
|
110
123
|
class VegaLiteState(TypedDict, total=False):
|
|
111
124
|
"""
|
|
@@ -323,7 +336,7 @@ def _marshall_chart_data(
|
|
|
323
336
|
dataset = proto.datasets.add()
|
|
324
337
|
dataset.name = str(dataset_name)
|
|
325
338
|
dataset.has_name = True
|
|
326
|
-
# The ID transformer (
|
|
339
|
+
# The ID transformer (_to_arrow_dataset function registered before conversion to dict)
|
|
327
340
|
# already serializes the data into Arrow IPC format (bytes) when the Altair object
|
|
328
341
|
# gets converted into the vega-lite spec dict.
|
|
329
342
|
# If its already in bytes, we don't need to serialize it here again.
|
|
@@ -364,41 +377,46 @@ def _convert_altair_to_vega_lite_spec(
|
|
|
364
377
|
"""Convert an Altair chart object to a Vega-Lite chart spec."""
|
|
365
378
|
import altair as alt
|
|
366
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
|
+
|
|
367
390
|
# Normally altair_chart.to_dict() would transform the dataframe used by the
|
|
368
391
|
# chart into an array of dictionaries. To avoid that, we install a
|
|
369
392
|
# transformer that replaces datasets with a reference by the object id of
|
|
370
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
|
+
)
|
|
371
411
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
"""Altair data transformer that serializes the data,
|
|
376
|
-
creates a stable name based on the hash of the data,
|
|
377
|
-
stores the bytes into the datasets mapping and
|
|
378
|
-
returns this name to have it be used in Altair.
|
|
379
|
-
"""
|
|
380
|
-
# Already serialize the data to be able to create a stable
|
|
381
|
-
# dataset name:
|
|
382
|
-
data_bytes = dataframe_util.convert_anything_to_arrow_bytes(data)
|
|
383
|
-
# Use the md5 hash of the data as the name:
|
|
384
|
-
name = calc_md5(str(data_bytes))
|
|
385
|
-
|
|
386
|
-
datasets[name] = data_bytes
|
|
387
|
-
return {"name": name}
|
|
388
|
-
|
|
389
|
-
alt.data_transformers.register("id", id_transform) # type: ignore[arg-type,attr-defined,unused-ignore]
|
|
390
|
-
|
|
391
|
-
# alt.themes was deprecated in Altair 5.5.0 in favor of alt.theme
|
|
392
|
-
alt_theme = (
|
|
393
|
-
alt.themes if type_util.is_altair_version_less_than("5.5.0") else alt.theme # ty: ignore[unresolved-attribute]
|
|
394
|
-
)
|
|
412
|
+
data_transformer = alt.data_transformers.enable(
|
|
413
|
+
"to_arrow_dataset", datasets=datasets
|
|
414
|
+
)
|
|
395
415
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
with alt.data_transformers.enable("id"): # type: ignore[attr-defined,unused-ignore]
|
|
401
|
-
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()
|
|
402
420
|
|
|
403
421
|
# Put datasets back into the chart dict:
|
|
404
422
|
chart_dict["datasets"] = datasets
|
|
@@ -704,17 +722,21 @@ class VegaChartsMixin:
|
|
|
704
722
|
fixed height. If the content is larger than the specified
|
|
705
723
|
height, scrolling is enabled.
|
|
706
724
|
|
|
707
|
-
use_container_width : bool
|
|
708
|
-
Whether to override
|
|
709
|
-
container.
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
Streamlit sets the
|
|
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:
|
|
728
|
+
|
|
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.
|
|
713
735
|
|
|
714
736
|
.. deprecated::
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
737
|
+
``use_container_width`` is deprecated and will be removed in a
|
|
738
|
+
future release. For ``use_container_width=True``, use
|
|
739
|
+
``width="stretch"``.
|
|
718
740
|
|
|
719
741
|
Examples
|
|
720
742
|
--------
|
|
@@ -791,25 +813,6 @@ class VegaChartsMixin:
|
|
|
791
813
|
height: 440px
|
|
792
814
|
|
|
793
815
|
"""
|
|
794
|
-
if use_container_width is not None:
|
|
795
|
-
show_deprecation_warning(
|
|
796
|
-
make_deprecated_name_warning(
|
|
797
|
-
"use_container_width",
|
|
798
|
-
"width",
|
|
799
|
-
"2025-12-31",
|
|
800
|
-
"For `use_container_width=True`, use `width='stretch'`. "
|
|
801
|
-
"For `use_container_width=False`, use `width='content'`.",
|
|
802
|
-
include_st_prefix=False,
|
|
803
|
-
),
|
|
804
|
-
show_in_browser=False,
|
|
805
|
-
)
|
|
806
|
-
if use_container_width:
|
|
807
|
-
width = "stretch"
|
|
808
|
-
elif not isinstance(width, int):
|
|
809
|
-
# This preserves the existing behavior of setting use_container_width
|
|
810
|
-
# to False combined with an integer width.
|
|
811
|
-
width = "content"
|
|
812
|
-
|
|
813
816
|
chart, add_rows_metadata = generate_chart(
|
|
814
817
|
chart_type=ChartType.LINE,
|
|
815
818
|
data=data,
|
|
@@ -824,12 +827,11 @@ class VegaChartsMixin:
|
|
|
824
827
|
use_container_width=(width == "stretch"),
|
|
825
828
|
)
|
|
826
829
|
|
|
827
|
-
validate_width(width, allow_content=True)
|
|
828
|
-
validate_height(height, allow_content=True)
|
|
829
830
|
return cast(
|
|
830
831
|
"DeltaGenerator",
|
|
831
832
|
self._altair_chart(
|
|
832
833
|
chart,
|
|
834
|
+
use_container_width=use_container_width,
|
|
833
835
|
theme="streamlit",
|
|
834
836
|
add_rows_metadata=add_rows_metadata,
|
|
835
837
|
width=width,
|
|
@@ -848,9 +850,9 @@ class VegaChartsMixin:
|
|
|
848
850
|
y_label: str | None = None,
|
|
849
851
|
color: str | Color | list[Color] | None = None,
|
|
850
852
|
stack: bool | ChartStackType | None = None,
|
|
851
|
-
width:
|
|
852
|
-
height:
|
|
853
|
-
use_container_width: bool =
|
|
853
|
+
width: Width = "stretch",
|
|
854
|
+
height: Height = "content",
|
|
855
|
+
use_container_width: bool | None = None,
|
|
854
856
|
) -> DeltaGenerator:
|
|
855
857
|
"""Display an area chart.
|
|
856
858
|
|
|
@@ -941,27 +943,46 @@ class VegaChartsMixin:
|
|
|
941
943
|
- ``"center"``: The areas are stacked and shifted to center their
|
|
942
944
|
baseline, which creates a steamgraph.
|
|
943
945
|
|
|
944
|
-
width :
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
946
|
+
width : "stretch", "content", or int
|
|
947
|
+
The width of the chart element. This can be one of the following:
|
|
948
|
+
|
|
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.
|
|
951
970
|
|
|
952
|
-
|
|
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:
|
|
953
974
|
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
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.
|
|
958
981
|
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
parent container. If ``use_container_width`` is ``False``,
|
|
964
|
-
Streamlit sets the chart's width according to ``width``.
|
|
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"``.
|
|
965
986
|
|
|
966
987
|
Examples
|
|
967
988
|
--------
|
|
@@ -1062,7 +1083,6 @@ class VegaChartsMixin:
|
|
|
1062
1083
|
height: 440px
|
|
1063
1084
|
|
|
1064
1085
|
"""
|
|
1065
|
-
|
|
1066
1086
|
# Check that the stack parameter is valid, raise more informative error message if not
|
|
1067
1087
|
maybe_raise_stack_warning(
|
|
1068
1088
|
stack,
|
|
@@ -1092,7 +1112,7 @@ class VegaChartsMixin:
|
|
|
1092
1112
|
width=width,
|
|
1093
1113
|
height=height,
|
|
1094
1114
|
stack=stack,
|
|
1095
|
-
use_container_width=
|
|
1115
|
+
use_container_width=(width == "stretch"),
|
|
1096
1116
|
)
|
|
1097
1117
|
return cast(
|
|
1098
1118
|
"DeltaGenerator",
|
|
@@ -1101,6 +1121,8 @@ class VegaChartsMixin:
|
|
|
1101
1121
|
use_container_width=use_container_width,
|
|
1102
1122
|
theme="streamlit",
|
|
1103
1123
|
add_rows_metadata=add_rows_metadata,
|
|
1124
|
+
width=width,
|
|
1125
|
+
height=height,
|
|
1104
1126
|
),
|
|
1105
1127
|
)
|
|
1106
1128
|
|
|
@@ -1117,9 +1139,9 @@ class VegaChartsMixin:
|
|
|
1117
1139
|
horizontal: bool = False,
|
|
1118
1140
|
sort: bool | str = True,
|
|
1119
1141
|
stack: bool | ChartStackType | None = None,
|
|
1120
|
-
width:
|
|
1121
|
-
height:
|
|
1122
|
-
use_container_width: bool =
|
|
1142
|
+
width: Width = "stretch",
|
|
1143
|
+
height: Height = "content",
|
|
1144
|
+
use_container_width: bool | None = None,
|
|
1123
1145
|
) -> DeltaGenerator:
|
|
1124
1146
|
"""Display a bar chart.
|
|
1125
1147
|
|
|
@@ -1230,27 +1252,46 @@ class VegaChartsMixin:
|
|
|
1230
1252
|
- ``"center"``: The bars are stacked and shifted to center the
|
|
1231
1253
|
total height around an axis.
|
|
1232
1254
|
|
|
1233
|
-
width :
|
|
1234
|
-
|
|
1235
|
-
``None`` (default), Streamlit sets the width of the chart to fit
|
|
1236
|
-
its contents according to the plotting library, up to the width of
|
|
1237
|
-
the parent container. If ``width`` is greater than the width of the
|
|
1238
|
-
parent container, Streamlit sets the chart width to match the width
|
|
1239
|
-
of the parent container.
|
|
1255
|
+
width : "stretch", "content", or int
|
|
1256
|
+
The width of the chart element. This can be one of the following:
|
|
1240
1257
|
|
|
1241
|
-
|
|
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.
|
|
1242
1266
|
|
|
1243
|
-
height :
|
|
1244
|
-
|
|
1245
|
-
``None`` (default), Streamlit sets the height of the chart to fit
|
|
1246
|
-
its contents according to the plotting library.
|
|
1267
|
+
height : "stretch", "content", or int
|
|
1268
|
+
The height of the chart element. This can be one of the following:
|
|
1247
1269
|
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
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.
|
|
1279
|
+
|
|
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:
|
|
1283
|
+
|
|
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.
|
|
1290
|
+
|
|
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"``.
|
|
1254
1295
|
|
|
1255
1296
|
Examples
|
|
1256
1297
|
--------
|
|
@@ -1368,7 +1409,6 @@ class VegaChartsMixin:
|
|
|
1368
1409
|
height: 440px
|
|
1369
1410
|
|
|
1370
1411
|
"""
|
|
1371
|
-
|
|
1372
1412
|
# Check that the stack parameter is valid, raise more informative error message if not
|
|
1373
1413
|
maybe_raise_stack_warning(
|
|
1374
1414
|
stack,
|
|
@@ -1410,6 +1450,8 @@ class VegaChartsMixin:
|
|
|
1410
1450
|
use_container_width=use_container_width,
|
|
1411
1451
|
theme="streamlit",
|
|
1412
1452
|
add_rows_metadata=add_rows_metadata,
|
|
1453
|
+
width=width,
|
|
1454
|
+
height=height,
|
|
1413
1455
|
),
|
|
1414
1456
|
)
|
|
1415
1457
|
|
|
@@ -1424,9 +1466,9 @@ class VegaChartsMixin:
|
|
|
1424
1466
|
y_label: str | None = None,
|
|
1425
1467
|
color: str | Color | list[Color] | None = None,
|
|
1426
1468
|
size: str | float | int | None = None,
|
|
1427
|
-
width:
|
|
1428
|
-
height:
|
|
1429
|
-
use_container_width: bool =
|
|
1469
|
+
width: Width = "stretch",
|
|
1470
|
+
height: Height = "content",
|
|
1471
|
+
use_container_width: bool | None = None,
|
|
1430
1472
|
) -> DeltaGenerator:
|
|
1431
1473
|
"""Display a scatterplot chart.
|
|
1432
1474
|
|
|
@@ -1511,27 +1553,46 @@ class VegaChartsMixin:
|
|
|
1511
1553
|
- The name of the column to use for the size. This allows each
|
|
1512
1554
|
datapoint to be represented by a circle of a different size.
|
|
1513
1555
|
|
|
1514
|
-
width :
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
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:
|
|
1521
1570
|
|
|
1522
|
-
|
|
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.
|
|
1523
1580
|
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
its contents according to the plotting library.
|
|
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:
|
|
1528
1584
|
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
Streamlit sets the width of the chart to
|
|
1533
|
-
|
|
1534
|
-
|
|
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.
|
|
1591
|
+
|
|
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"``.
|
|
1535
1596
|
|
|
1536
1597
|
Examples
|
|
1537
1598
|
--------
|
|
@@ -1616,7 +1677,6 @@ class VegaChartsMixin:
|
|
|
1616
1677
|
height: 440px
|
|
1617
1678
|
|
|
1618
1679
|
"""
|
|
1619
|
-
|
|
1620
1680
|
chart, add_rows_metadata = generate_chart(
|
|
1621
1681
|
chart_type=ChartType.SCATTER,
|
|
1622
1682
|
data=data,
|
|
@@ -1628,7 +1688,7 @@ class VegaChartsMixin:
|
|
|
1628
1688
|
size_from_user=size,
|
|
1629
1689
|
width=width,
|
|
1630
1690
|
height=height,
|
|
1631
|
-
use_container_width=
|
|
1691
|
+
use_container_width=(width == "stretch"),
|
|
1632
1692
|
)
|
|
1633
1693
|
return cast(
|
|
1634
1694
|
"DeltaGenerator",
|
|
@@ -1637,6 +1697,8 @@ class VegaChartsMixin:
|
|
|
1637
1697
|
use_container_width=use_container_width,
|
|
1638
1698
|
theme="streamlit",
|
|
1639
1699
|
add_rows_metadata=add_rows_metadata,
|
|
1700
|
+
width=width,
|
|
1701
|
+
height=height,
|
|
1640
1702
|
),
|
|
1641
1703
|
)
|
|
1642
1704
|
|
|
@@ -1646,6 +1708,8 @@ class VegaChartsMixin:
|
|
|
1646
1708
|
self,
|
|
1647
1709
|
altair_chart: AltairChart,
|
|
1648
1710
|
*,
|
|
1711
|
+
width: Width | None = None,
|
|
1712
|
+
height: Height = "content",
|
|
1649
1713
|
use_container_width: bool | None = None,
|
|
1650
1714
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1651
1715
|
key: Key | None = None,
|
|
@@ -1659,6 +1723,8 @@ class VegaChartsMixin:
|
|
|
1659
1723
|
self,
|
|
1660
1724
|
altair_chart: AltairChart,
|
|
1661
1725
|
*,
|
|
1726
|
+
width: Width | None = None,
|
|
1727
|
+
height: Height = "content",
|
|
1662
1728
|
use_container_width: bool | None = None,
|
|
1663
1729
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1664
1730
|
key: Key | None = None,
|
|
@@ -1671,6 +1737,8 @@ class VegaChartsMixin:
|
|
|
1671
1737
|
self,
|
|
1672
1738
|
altair_chart: AltairChart,
|
|
1673
1739
|
*,
|
|
1740
|
+
width: Width | None = None,
|
|
1741
|
+
height: Height = "content",
|
|
1674
1742
|
use_container_width: bool | None = None,
|
|
1675
1743
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1676
1744
|
key: Key | None = None,
|
|
@@ -1690,6 +1758,39 @@ class VegaChartsMixin:
|
|
|
1690
1758
|
https://altair-viz.github.io/gallery/ for examples of graph
|
|
1691
1759
|
descriptions.
|
|
1692
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
|
+
|
|
1693
1794
|
use_container_width : bool or None
|
|
1694
1795
|
Whether to override the chart's native width with the width of
|
|
1695
1796
|
the parent container. This can be one of the following:
|
|
@@ -1704,6 +1805,11 @@ class VegaChartsMixin:
|
|
|
1704
1805
|
contents according to the plotting library, up to the width of
|
|
1705
1806
|
the parent container.
|
|
1706
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
|
+
|
|
1707
1813
|
theme : "streamlit" or None
|
|
1708
1814
|
The theme of the chart. If ``theme`` is ``"streamlit"`` (default),
|
|
1709
1815
|
Streamlit uses its own design default. If ``theme`` is ``None``,
|
|
@@ -1796,6 +1902,8 @@ class VegaChartsMixin:
|
|
|
1796
1902
|
"""
|
|
1797
1903
|
return self._altair_chart(
|
|
1798
1904
|
altair_chart=altair_chart,
|
|
1905
|
+
width=width,
|
|
1906
|
+
height=height,
|
|
1799
1907
|
use_container_width=use_container_width,
|
|
1800
1908
|
theme=theme,
|
|
1801
1909
|
key=key,
|
|
@@ -1810,6 +1918,8 @@ class VegaChartsMixin:
|
|
|
1810
1918
|
data: Data = None,
|
|
1811
1919
|
spec: VegaLiteSpec | None = None,
|
|
1812
1920
|
*,
|
|
1921
|
+
width: Width | None = None,
|
|
1922
|
+
height: Height = "content",
|
|
1813
1923
|
use_container_width: bool | None = None,
|
|
1814
1924
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1815
1925
|
key: Key | None = None,
|
|
@@ -1825,6 +1935,8 @@ class VegaChartsMixin:
|
|
|
1825
1935
|
data: Data = None,
|
|
1826
1936
|
spec: VegaLiteSpec | None = None,
|
|
1827
1937
|
*,
|
|
1938
|
+
width: Width | None = None,
|
|
1939
|
+
height: Height = "content",
|
|
1828
1940
|
use_container_width: bool | None = None,
|
|
1829
1941
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1830
1942
|
key: Key | None = None,
|
|
@@ -1839,6 +1951,8 @@ class VegaChartsMixin:
|
|
|
1839
1951
|
data: Data = None,
|
|
1840
1952
|
spec: VegaLiteSpec | None = None,
|
|
1841
1953
|
*,
|
|
1954
|
+
width: Width | None = None,
|
|
1955
|
+
height: Height = "content",
|
|
1842
1956
|
use_container_width: bool | None = None,
|
|
1843
1957
|
theme: Literal["streamlit"] | None = "streamlit",
|
|
1844
1958
|
key: Key | None = None,
|
|
@@ -1863,6 +1977,39 @@ class VegaChartsMixin:
|
|
|
1863
1977
|
to both ``data`` and ``spec``. See
|
|
1864
1978
|
https://vega.github.io/vega-lite/docs/ for more info.
|
|
1865
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
|
+
|
|
1866
2013
|
use_container_width : bool or None
|
|
1867
2014
|
Whether to override the chart's native width with the width of
|
|
1868
2015
|
the parent container. This can be one of the following:
|
|
@@ -1877,6 +2024,11 @@ class VegaChartsMixin:
|
|
|
1877
2024
|
contents according to the plotting library, up to the width of
|
|
1878
2025
|
the parent container.
|
|
1879
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
|
+
|
|
1880
2032
|
theme : "streamlit" or None
|
|
1881
2033
|
The theme of the chart. If ``theme`` is ``"streamlit"`` (default),
|
|
1882
2034
|
Streamlit uses its own design default. If ``theme`` is ``None``,
|
|
@@ -1986,6 +2138,8 @@ class VegaChartsMixin:
|
|
|
1986
2138
|
key=key,
|
|
1987
2139
|
on_select=on_select,
|
|
1988
2140
|
selection_mode=selection_mode,
|
|
2141
|
+
width=width,
|
|
2142
|
+
height=height,
|
|
1989
2143
|
**kwargs,
|
|
1990
2144
|
)
|
|
1991
2145
|
|
|
@@ -1999,7 +2153,7 @@ class VegaChartsMixin:
|
|
|
1999
2153
|
selection_mode: str | Iterable[str] | None = None,
|
|
2000
2154
|
add_rows_metadata: AddRowsMetadata | None = None,
|
|
2001
2155
|
width: Width | None = None,
|
|
2002
|
-
height: Height
|
|
2156
|
+
height: Height = "content",
|
|
2003
2157
|
) -> DeltaGenerator | VegaLiteState:
|
|
2004
2158
|
"""Internal method to enqueue a vega-lite chart element based on an Altair chart.
|
|
2005
2159
|
|
|
@@ -2039,14 +2193,13 @@ class VegaChartsMixin:
|
|
|
2039
2193
|
selection_mode: str | Iterable[str] | None = None,
|
|
2040
2194
|
add_rows_metadata: AddRowsMetadata | None = None,
|
|
2041
2195
|
width: Width | None = None,
|
|
2042
|
-
height: Height
|
|
2196
|
+
height: Height = "content",
|
|
2043
2197
|
**kwargs: Any,
|
|
2044
2198
|
) -> DeltaGenerator | VegaLiteState:
|
|
2045
2199
|
"""Internal method to enqueue a vega-lite chart element based on a vega-lite spec.
|
|
2046
2200
|
|
|
2047
2201
|
See the `vega_lite_chart` method docstring for more information.
|
|
2048
2202
|
"""
|
|
2049
|
-
|
|
2050
2203
|
if theme not in ["streamlit", None]:
|
|
2051
2204
|
raise StreamlitAPIException(
|
|
2052
2205
|
f'You set theme="{theme}" while Streamlit charts only support '
|
|
@@ -2085,22 +2238,48 @@ class VegaChartsMixin:
|
|
|
2085
2238
|
if spec is None:
|
|
2086
2239
|
spec = {}
|
|
2087
2240
|
|
|
2088
|
-
# Set the default value for
|
|
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.
|
|
2089
2243
|
if use_container_width is None and width is None:
|
|
2090
2244
|
# Some multi-view charts (facet, horizontal concatenation, and repeat;
|
|
2091
2245
|
# see https://altair-viz.github.io/user_guide/compound_charts.html)
|
|
2092
|
-
# don't work well with `
|
|
2246
|
+
# don't work well with `width=stretch`, so we disable it for
|
|
2093
2247
|
# those charts (see https://github.com/streamlit/streamlit/issues/9091).
|
|
2094
2248
|
# All other charts (including vertical concatenation) default to
|
|
2095
|
-
# `
|
|
2249
|
+
# `width=stretch` unless width is provided.
|
|
2096
2250
|
is_facet_chart = "facet" in spec or (
|
|
2097
2251
|
"encoding" in spec
|
|
2098
2252
|
and (any(x in spec["encoding"] for x in ["row", "column", "facet"]))
|
|
2099
2253
|
)
|
|
2100
|
-
|
|
2101
|
-
|
|
2254
|
+
width = (
|
|
2255
|
+
"stretch"
|
|
2256
|
+
if not (is_facet_chart or "hconcat" in spec or "repeat" in spec)
|
|
2257
|
+
else "content"
|
|
2102
2258
|
)
|
|
2103
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,
|
|
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)
|
|
2282
|
+
|
|
2104
2283
|
vega_lite_proto = ArrowVegaLiteChartProto()
|
|
2105
2284
|
|
|
2106
2285
|
use_container_width_for_spec = (
|
|
@@ -2108,11 +2287,13 @@ class VegaChartsMixin:
|
|
|
2108
2287
|
if use_container_width is not None
|
|
2109
2288
|
else width == "stretch"
|
|
2110
2289
|
)
|
|
2290
|
+
|
|
2111
2291
|
spec = _prepare_vega_lite_spec(spec, use_container_width_for_spec, **kwargs)
|
|
2112
2292
|
_marshall_chart_data(vega_lite_proto, spec, data)
|
|
2113
2293
|
|
|
2114
2294
|
# Prevent the spec from changing across reruns:
|
|
2115
2295
|
vega_lite_proto.spec = _stabilize_vega_json_spec(json.dumps(spec))
|
|
2296
|
+
|
|
2116
2297
|
if use_container_width is not None:
|
|
2117
2298
|
vega_lite_proto.use_container_width = use_container_width
|
|
2118
2299
|
vega_lite_proto.theme = theme or ""
|
|
@@ -2158,32 +2339,42 @@ class VegaChartsMixin:
|
|
|
2158
2339
|
value_type="string_value",
|
|
2159
2340
|
)
|
|
2160
2341
|
|
|
2161
|
-
self.dg._enqueue(
|
|
2162
|
-
"arrow_vega_lite_chart",
|
|
2163
|
-
vega_lite_proto,
|
|
2164
|
-
add_rows_metadata=add_rows_metadata,
|
|
2165
|
-
)
|
|
2166
|
-
return widget_state.value
|
|
2167
|
-
|
|
2168
|
-
# Handle layout config for width/height parameters
|
|
2169
|
-
if width is not None or height is not None:
|
|
2170
2342
|
layout_config = LayoutConfig(width=width, height=height)
|
|
2171
|
-
|
|
2343
|
+
self.dg._enqueue(
|
|
2172
2344
|
"arrow_vega_lite_chart",
|
|
2173
2345
|
vega_lite_proto,
|
|
2174
2346
|
add_rows_metadata=add_rows_metadata,
|
|
2175
2347
|
layout_config=layout_config,
|
|
2176
2348
|
)
|
|
2349
|
+
return widget_state.value
|
|
2177
2350
|
|
|
2178
2351
|
# If its not used with selections activated, just return
|
|
2179
2352
|
# the delta generator related to this element.
|
|
2353
|
+
layout_config = LayoutConfig(width=width, height=height)
|
|
2180
2354
|
return self.dg._enqueue(
|
|
2181
2355
|
"arrow_vega_lite_chart",
|
|
2182
2356
|
vega_lite_proto,
|
|
2183
2357
|
add_rows_metadata=add_rows_metadata,
|
|
2358
|
+
layout_config=layout_config,
|
|
2184
2359
|
)
|
|
2185
2360
|
|
|
2186
2361
|
@property
|
|
2187
2362
|
def dg(self) -> DeltaGenerator:
|
|
2188
2363
|
"""Get our DeltaGenerator."""
|
|
2189
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}
|