streamlit-nightly 1.36.1.dev20240707__py2.py3-none-any.whl → 1.36.1.dev20240709__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit/code_util.py +1 -1
- streamlit/commands/execution_control.py +6 -2
- streamlit/commands/logo.py +5 -1
- streamlit/commands/navigation.py +5 -5
- streamlit/connections/base_connection.py +1 -1
- streamlit/connections/snowpark_connection.py +1 -1
- streamlit/connections/sql_connection.py +5 -1
- streamlit/delta_generator.py +14 -14
- streamlit/elements/arrow.py +19 -11
- streamlit/elements/bokeh_chart.py +2 -6
- streamlit/elements/code.py +1 -1
- streamlit/elements/deck_gl_json_chart.py +32 -29
- streamlit/elements/doc_string.py +1 -1
- streamlit/elements/empty.py +1 -1
- streamlit/elements/exception.py +1 -1
- streamlit/elements/form.py +7 -8
- streamlit/elements/graphviz_chart.py +13 -13
- streamlit/elements/heading.py +6 -6
- streamlit/elements/html.py +3 -1
- streamlit/elements/image.py +1 -1
- streamlit/elements/json.py +12 -10
- streamlit/elements/layouts.py +21 -21
- streamlit/elements/lib/built_in_chart_utils.py +21 -7
- streamlit/elements/markdown.py +3 -3
- streamlit/elements/media.py +2 -2
- streamlit/elements/metric.py +4 -4
- streamlit/elements/spinner.py +1 -1
- streamlit/elements/text.py +1 -1
- streamlit/elements/vega_charts.py +87 -43
- streamlit/elements/widgets/button.py +5 -5
- streamlit/elements/widgets/file_uploader.py +3 -1
- streamlit/elements/widgets/multiselect.py +2 -1
- streamlit/elements/widgets/number_input.py +6 -2
- streamlit/elements/widgets/radio.py +6 -1
- streamlit/elements/widgets/select_slider.py +21 -3
- streamlit/elements/widgets/selectbox.py +6 -5
- streamlit/elements/widgets/slider.py +5 -6
- streamlit/elements/widgets/text_widgets.py +1 -1
- streamlit/elements/write.py +17 -13
- streamlit/runtime/caching/cache_data_api.py +3 -3
- streamlit/runtime/caching/cache_resource_api.py +3 -3
- streamlit/runtime/caching/legacy_cache_api.py +1 -1
- streamlit/runtime/connection_factory.py +10 -4
- streamlit/static/asset-manifest.json +5 -5
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{2736.4336e2b9.chunk.js → 2736.7d516fcc.chunk.js} +1 -1
- streamlit/static/static/js/3301.0cd98943.chunk.js +1 -0
- streamlit/static/static/js/7175.4cdaec13.chunk.js +1 -0
- streamlit/static/static/js/{main.28e3c6e9.js → main.2bfed63a.js} +2 -2
- streamlit/testing/v1/util.py +2 -2
- streamlit/type_util.py +1 -1
- {streamlit_nightly-1.36.1.dev20240707.dist-info → streamlit_nightly-1.36.1.dev20240709.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.36.1.dev20240707.dist-info → streamlit_nightly-1.36.1.dev20240709.dist-info}/RECORD +58 -58
- {streamlit_nightly-1.36.1.dev20240707.dist-info → streamlit_nightly-1.36.1.dev20240709.dist-info}/WHEEL +1 -1
- streamlit/static/static/js/3301.1d1b10bb.chunk.js +0 -1
- streamlit/static/static/js/7175.8f4014ec.chunk.js +0 -1
- /streamlit/static/static/js/{main.28e3c6e9.js.LICENSE.txt → main.2bfed63a.js.LICENSE.txt} +0 -0
- {streamlit_nightly-1.36.1.dev20240707.data → streamlit_nightly-1.36.1.dev20240709.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.36.1.dev20240707.dist-info → streamlit_nightly-1.36.1.dev20240709.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.36.1.dev20240707.dist-info → streamlit_nightly-1.36.1.dev20240709.dist-info}/top_level.txt +0 -0
streamlit/elements/media.py
CHANGED
@@ -288,7 +288,7 @@ class MediaMixin:
|
|
288
288
|
-------
|
289
289
|
>>> import streamlit as st
|
290
290
|
>>>
|
291
|
-
>>> video_file = open(
|
291
|
+
>>> video_file = open("myvideo.mp4", "rb")
|
292
292
|
>>> video_bytes = video_file.read()
|
293
293
|
>>>
|
294
294
|
>>> st.video(video_bytes)
|
@@ -376,7 +376,7 @@ def _reshape_youtube_url(url: str) -> str | None:
|
|
376
376
|
|
377
377
|
Example
|
378
378
|
-------
|
379
|
-
>>> print(_reshape_youtube_url(
|
379
|
+
>>> print(_reshape_youtube_url("https://youtu.be/_T8LGqJtuGc"))
|
380
380
|
|
381
381
|
.. output::
|
382
382
|
https://www.youtube.com/embed/_T8LGqJtuGc
|
streamlit/elements/metric.py
CHANGED
@@ -141,11 +141,11 @@ class MetricMixin:
|
|
141
141
|
|
142
142
|
>>> import streamlit as st
|
143
143
|
>>>
|
144
|
-
>>> st.metric(label="Gas price", value=4, delta=-0.5,
|
145
|
-
... delta_color="inverse")
|
144
|
+
>>> st.metric(label="Gas price", value=4, delta=-0.5, delta_color="inverse")
|
146
145
|
>>>
|
147
|
-
>>> st.metric(
|
148
|
-
... delta_color="off"
|
146
|
+
>>> st.metric(
|
147
|
+
... label="Active developers", value=123, delta=123, delta_color="off"
|
148
|
+
... )
|
149
149
|
|
150
150
|
.. output::
|
151
151
|
https://doc-metric-example3.streamlit.app/
|
streamlit/elements/spinner.py
CHANGED
@@ -39,7 +39,7 @@ def spinner(text: str = "In progress...", *, _cache: bool = False) -> Iterator[N
|
|
39
39
|
>>>
|
40
40
|
>>> with st.spinner('Wait for it...'):
|
41
41
|
>>> time.sleep(5)
|
42
|
-
>>> st.success(
|
42
|
+
>>> st.success("Done!")
|
43
43
|
|
44
44
|
"""
|
45
45
|
from streamlit.proto.Spinner_pb2 import Spinner as SpinnerProto
|
streamlit/elements/text.py
CHANGED
@@ -42,6 +42,7 @@ from streamlit.elements.lib.built_in_chart_utils import (
|
|
42
42
|
ChartStackType,
|
43
43
|
ChartType,
|
44
44
|
generate_chart,
|
45
|
+
maybe_raise_stack_warning,
|
45
46
|
)
|
46
47
|
from streamlit.elements.lib.event_utils import AttributeDictionary
|
47
48
|
from streamlit.elements.lib.policies import check_widget_policies
|
@@ -185,7 +186,9 @@ class VegaLiteState(TypedDict, total=False):
|
|
185
186
|
... },
|
186
187
|
... }
|
187
188
|
>>>
|
188
|
-
>>> event = st.vega_lite_chart(
|
189
|
+
>>> event = st.vega_lite_chart(
|
190
|
+
... st.session_state.data, spec, key="vega_chart", on_select="rerun"
|
191
|
+
... )
|
189
192
|
>>>
|
190
193
|
>>> event
|
191
194
|
|
@@ -682,11 +685,11 @@ class VegaChartsMixin:
|
|
682
685
|
>>> import numpy as np
|
683
686
|
>>>
|
684
687
|
>>> chart_data = pd.DataFrame(
|
685
|
-
...
|
686
|
-
...
|
687
|
-
...
|
688
|
-
...
|
689
|
-
...
|
688
|
+
... {
|
689
|
+
... "col1": np.random.randn(20),
|
690
|
+
... "col2": np.random.randn(20),
|
691
|
+
... "col3": np.random.choice(["A", "B", "C"], 20),
|
692
|
+
... }
|
690
693
|
... )
|
691
694
|
>>>
|
692
695
|
>>> st.line_chart(chart_data, x="col1", y="col2", color="col3")
|
@@ -703,10 +706,15 @@ class VegaChartsMixin:
|
|
703
706
|
>>> import pandas as pd
|
704
707
|
>>> import numpy as np
|
705
708
|
>>>
|
706
|
-
>>> chart_data = pd.DataFrame(
|
709
|
+
>>> chart_data = pd.DataFrame(
|
710
|
+
... np.random.randn(20, 3), columns=["col1", "col2", "col3"]
|
711
|
+
... )
|
707
712
|
>>>
|
708
713
|
>>> st.line_chart(
|
709
|
-
...
|
714
|
+
... chart_data,
|
715
|
+
... x="col1",
|
716
|
+
... y=["col2", "col3"],
|
717
|
+
... color=["#FF0000", "#0000FF"], # Optional
|
710
718
|
... )
|
711
719
|
|
712
720
|
.. output::
|
@@ -747,6 +755,7 @@ class VegaChartsMixin:
|
|
747
755
|
x_label: str | None = None,
|
748
756
|
y_label: str | None = None,
|
749
757
|
color: str | Color | list[Color] | None = None,
|
758
|
+
stack: bool | ChartStackType | None = None,
|
750
759
|
width: int | None = None,
|
751
760
|
height: int | None = None,
|
752
761
|
use_container_width: bool = True,
|
@@ -830,6 +839,13 @@ class VegaChartsMixin:
|
|
830
839
|
as the number of y values (e.g. ``color=["#fd0", "#f0f", "#04f"]``
|
831
840
|
for three lines).
|
832
841
|
|
842
|
+
stack : bool, "normalize", "center", or None
|
843
|
+
Whether to stack the areas. If this is ``None`` (default), uses
|
844
|
+
Vega's default. If ``True``, stacks the areas on top of one another.
|
845
|
+
If ``False``, overlays the areas without stacking. If "normalize",
|
846
|
+
the areas are stacked and normalized to 100%. If "center", the areas
|
847
|
+
are stacked and shifted to center their baseline (produces steamgraph).
|
848
|
+
|
833
849
|
width : int or None
|
834
850
|
Desired width of the chart expressed in pixels. If ``width`` is
|
835
851
|
``None`` (default), Streamlit sets the width of the chart to fit
|
@@ -875,11 +891,11 @@ class VegaChartsMixin:
|
|
875
891
|
>>> import numpy as np
|
876
892
|
>>>
|
877
893
|
>>> chart_data = pd.DataFrame(
|
878
|
-
...
|
879
|
-
...
|
880
|
-
...
|
881
|
-
...
|
882
|
-
...
|
894
|
+
... {
|
895
|
+
... "col1": np.random.randn(20),
|
896
|
+
... "col2": np.random.randn(20),
|
897
|
+
... "col3": np.random.choice(["A", "B", "C"], 20),
|
898
|
+
... }
|
883
899
|
... )
|
884
900
|
>>>
|
885
901
|
>>> st.area_chart(chart_data, x="col1", y="col2", color="col3")
|
@@ -896,10 +912,15 @@ class VegaChartsMixin:
|
|
896
912
|
>>> import pandas as pd
|
897
913
|
>>> import numpy as np
|
898
914
|
>>>
|
899
|
-
>>> chart_data = pd.DataFrame(
|
915
|
+
>>> chart_data = pd.DataFrame(
|
916
|
+
... np.random.randn(20, 3), columns=["col1", "col2", "col3"]
|
917
|
+
... )
|
900
918
|
>>>
|
901
919
|
>>> st.area_chart(
|
902
|
-
...
|
920
|
+
... chart_data,
|
921
|
+
... x="col1",
|
922
|
+
... y=["col2", "col3"],
|
923
|
+
... color=["#FF0000", "#0000FF"], # Optional
|
903
924
|
... )
|
904
925
|
|
905
926
|
.. output::
|
@@ -908,6 +929,18 @@ class VegaChartsMixin:
|
|
908
929
|
|
909
930
|
"""
|
910
931
|
|
932
|
+
# Check that the stack parameter is valid, raise more informative error message if not
|
933
|
+
maybe_raise_stack_warning(
|
934
|
+
stack,
|
935
|
+
"st.area_chart",
|
936
|
+
"https://docs.streamlit.io/develop/api-reference/charts/st.area_chart",
|
937
|
+
)
|
938
|
+
|
939
|
+
# st.area_chart's stack=False option translates to a "layered" area chart for vega. We reserve stack=False for
|
940
|
+
# grouped/non-stacked bar charts, so we need to translate False to "layered" here.
|
941
|
+
if stack is False:
|
942
|
+
stack = "layered"
|
943
|
+
|
911
944
|
chart, add_rows_metadata = generate_chart(
|
912
945
|
chart_type=ChartType.AREA,
|
913
946
|
data=data,
|
@@ -919,6 +952,7 @@ class VegaChartsMixin:
|
|
919
952
|
size_from_user=None,
|
920
953
|
width=width,
|
921
954
|
height=height,
|
955
|
+
stack=stack,
|
922
956
|
)
|
923
957
|
return cast(
|
924
958
|
"DeltaGenerator",
|
@@ -1033,8 +1067,8 @@ class VegaChartsMixin:
|
|
1033
1067
|
|
1034
1068
|
stack : bool, "normalize", "center", "layered", or None
|
1035
1069
|
Whether to stack the bars. If this is ``None`` (default), uses Vega's
|
1036
|
-
default. If
|
1037
|
-
If
|
1070
|
+
default. If ``True``, the bars are stacked on top of each other.
|
1071
|
+
If ``False``, the bars are displayed side by side. If "normalize",
|
1038
1072
|
the bars are stacked and normalized to 100%. If "center", the bars are
|
1039
1073
|
stacked around a central axis. If "layered", the bars are stacked on top
|
1040
1074
|
of one another.
|
@@ -1084,11 +1118,11 @@ class VegaChartsMixin:
|
|
1084
1118
|
>>> import numpy as np
|
1085
1119
|
>>>
|
1086
1120
|
>>> chart_data = pd.DataFrame(
|
1087
|
-
...
|
1088
|
-
...
|
1089
|
-
...
|
1090
|
-
...
|
1091
|
-
...
|
1121
|
+
... {
|
1122
|
+
... "col1": list(range(20)) * 3,
|
1123
|
+
... "col2": np.random.randn(60),
|
1124
|
+
... "col3": ["A"] * 20 + ["B"] * 20 + ["C"] * 20,
|
1125
|
+
... }
|
1092
1126
|
... )
|
1093
1127
|
>>>
|
1094
1128
|
>>> st.bar_chart(chart_data, x="col1", y="col2", color="col3")
|
@@ -1106,11 +1140,18 @@ class VegaChartsMixin:
|
|
1106
1140
|
>>> import numpy as np
|
1107
1141
|
>>>
|
1108
1142
|
>>> chart_data = pd.DataFrame(
|
1109
|
-
...
|
1143
|
+
... {
|
1144
|
+
... "col1": list(range(20)),
|
1145
|
+
... "col2": np.random.randn(20),
|
1146
|
+
... "col3": np.random.randn(20),
|
1147
|
+
... }
|
1110
1148
|
... )
|
1111
1149
|
>>>
|
1112
1150
|
>>> st.bar_chart(
|
1113
|
-
...
|
1151
|
+
... chart_data,
|
1152
|
+
... x="col1",
|
1153
|
+
... y=["col2", "col3"],
|
1154
|
+
... color=["#FF0000", "#0000FF"], # Optional
|
1114
1155
|
... )
|
1115
1156
|
|
1116
1157
|
.. output::
|
@@ -1132,20 +1173,19 @@ class VegaChartsMixin:
|
|
1132
1173
|
|
1133
1174
|
"""
|
1134
1175
|
|
1176
|
+
# Check that the stack parameter is valid, raise more informative error message if not
|
1177
|
+
maybe_raise_stack_warning(
|
1178
|
+
stack,
|
1179
|
+
"st.bar_chart",
|
1180
|
+
"https://docs.streamlit.io/develop/api-reference/charts/st.bar_chart",
|
1181
|
+
)
|
1182
|
+
|
1135
1183
|
# Offset encodings (used for non-stacked/grouped bar charts) are not supported in Altair < 5.0.0
|
1136
1184
|
if type_util.is_altair_version_less_than("5.0.0") and stack is False:
|
1137
1185
|
raise StreamlitAPIException(
|
1138
1186
|
"Streamlit does not support non-stacked (grouped) bar charts with Altair 4.x. Please upgrade to Version 5."
|
1139
1187
|
)
|
1140
1188
|
|
1141
|
-
# Check that the stack parameter is valid, raise more informative error message if not
|
1142
|
-
VALID_STACK_TYPES = (None, True, False, "normalize", "center", "layered")
|
1143
|
-
if stack not in VALID_STACK_TYPES:
|
1144
|
-
raise StreamlitAPIException(
|
1145
|
-
f'Invalid value for stack parameter: {stack}. Stack must be one of True, False, "normalize", "center", "layered" or None. '
|
1146
|
-
"See documentation for `st.bar_chart` [here](https://docs.streamlit.io/develop/api-reference/charts/st.bar_chart) for more information."
|
1147
|
-
)
|
1148
|
-
|
1149
1189
|
bar_chart_type = (
|
1150
1190
|
ChartType.HORIZONTAL_BAR if horizontal else ChartType.VERTICAL_BAR
|
1151
1191
|
)
|
@@ -1320,15 +1360,17 @@ class VegaChartsMixin:
|
|
1320
1360
|
>>> import pandas as pd
|
1321
1361
|
>>> import numpy as np
|
1322
1362
|
>>>
|
1323
|
-
>>> chart_data = pd.DataFrame(
|
1324
|
-
|
1363
|
+
>>> chart_data = pd.DataFrame(
|
1364
|
+
... np.random.randn(20, 3), columns=["col1", "col2", "col3"]
|
1365
|
+
... )
|
1366
|
+
>>> chart_data["col4"] = np.random.choice(["A", "B", "C"], 20)
|
1325
1367
|
>>>
|
1326
1368
|
>>> st.scatter_chart(
|
1327
1369
|
... chart_data,
|
1328
|
-
... x=
|
1329
|
-
... y=
|
1330
|
-
... color=
|
1331
|
-
... size=
|
1370
|
+
... x="col1",
|
1371
|
+
... y="col2",
|
1372
|
+
... color="col4",
|
1373
|
+
... size="col3",
|
1332
1374
|
... )
|
1333
1375
|
|
1334
1376
|
.. output::
|
@@ -1343,14 +1385,16 @@ class VegaChartsMixin:
|
|
1343
1385
|
>>> import pandas as pd
|
1344
1386
|
>>> import numpy as np
|
1345
1387
|
>>>
|
1346
|
-
>>> chart_data = pd.DataFrame(
|
1388
|
+
>>> chart_data = pd.DataFrame(
|
1389
|
+
... np.random.randn(20, 4), columns=["col1", "col2", "col3", "col4"]
|
1390
|
+
... )
|
1347
1391
|
>>>
|
1348
1392
|
>>> st.scatter_chart(
|
1349
1393
|
... chart_data,
|
1350
|
-
... x=
|
1351
|
-
... y=[
|
1352
|
-
... size=
|
1353
|
-
... color=[
|
1394
|
+
... x="col1",
|
1395
|
+
... y=["col2", "col3"],
|
1396
|
+
... size="col4",
|
1397
|
+
... color=["#FF0000", "#0000FF"], # Optional
|
1354
1398
|
... )
|
1355
1399
|
|
1356
1400
|
.. output::
|
@@ -331,11 +331,11 @@ class ButtonMixin:
|
|
331
331
|
>>>
|
332
332
|
>>> with open("flower.png", "rb") as file:
|
333
333
|
... btn = st.download_button(
|
334
|
-
...
|
335
|
-
...
|
336
|
-
...
|
337
|
-
...
|
338
|
-
...
|
334
|
+
... label="Download image",
|
335
|
+
... data=file,
|
336
|
+
... file_name="flower.png",
|
337
|
+
... mime="image/png",
|
338
|
+
... )
|
339
339
|
|
340
340
|
.. output::
|
341
341
|
https://doc-download-buton.streamlit.app/
|
@@ -359,7 +359,9 @@ class FileUploaderMixin:
|
|
359
359
|
|
360
360
|
>>> import streamlit as st
|
361
361
|
>>>
|
362
|
-
>>> uploaded_files = st.file_uploader(
|
362
|
+
>>> uploaded_files = st.file_uploader(
|
363
|
+
... "Choose a CSV file", accept_multiple_files=True
|
364
|
+
... )
|
363
365
|
>>> for uploaded_file in uploaded_files:
|
364
366
|
... bytes_data = uploaded_file.read()
|
365
367
|
... st.write("filename:", uploaded_file.name)
|
@@ -241,7 +241,8 @@ class MultiSelectMixin:
|
|
241
241
|
>>> options = st.multiselect(
|
242
242
|
... "What are your favorite colors",
|
243
243
|
... ["Green", "Yellow", "Red", "Blue"],
|
244
|
-
... ["Yellow", "Red"]
|
244
|
+
... ["Yellow", "Red"],
|
245
|
+
... )
|
245
246
|
>>>
|
246
247
|
>>> st.write("You selected:", options)
|
247
248
|
|
@@ -191,7 +191,9 @@ class NumberInputMixin:
|
|
191
191
|
format : str or None
|
192
192
|
A printf-style format string controlling how the interface should
|
193
193
|
display numbers. Output must be purely numeric. This does not impact
|
194
|
-
the return value.
|
194
|
+
the return value. Formatting is handled by [sprintf.js](https://github.com/alexei/sprintf.js).
|
195
|
+
This can be used to adjust decimal precision in the displayed result. For example,
|
196
|
+
``'%0.1f'`` to only show 1 digit after the decimal.
|
195
197
|
key : str or int
|
196
198
|
An optional string or integer to use as the unique key for the widget.
|
197
199
|
If this is omitted, a key will be generated for the widget
|
@@ -238,7 +240,9 @@ class NumberInputMixin:
|
|
238
240
|
|
239
241
|
>>> import streamlit as st
|
240
242
|
>>>
|
241
|
-
>>> number = st.number_input(
|
243
|
+
>>> number = st.number_input(
|
244
|
+
... "Insert a number", value=None, placeholder="Type a number..."
|
245
|
+
... )
|
242
246
|
>>> st.write("The current number is ", number)
|
243
247
|
|
244
248
|
.. output::
|
@@ -188,7 +188,12 @@ class RadioMixin:
|
|
188
188
|
>>> genre = st.radio(
|
189
189
|
... "What's your favorite movie genre",
|
190
190
|
... [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"],
|
191
|
-
... captions
|
191
|
+
... captions=[
|
192
|
+
... "Laugh out loud.",
|
193
|
+
... "Get the popcorn.",
|
194
|
+
... "Never stop learning.",
|
195
|
+
... ],
|
196
|
+
... )
|
192
197
|
>>>
|
193
198
|
>>> if genre == ":rainbow[Comedy]":
|
194
199
|
... st.write("You selected comedy.")
|
@@ -209,7 +209,16 @@ class SelectSliderMixin:
|
|
209
209
|
>>>
|
210
210
|
>>> color = st.select_slider(
|
211
211
|
... "Select a color of the rainbow",
|
212
|
-
... options=[
|
212
|
+
... options=[
|
213
|
+
... "red",
|
214
|
+
... "orange",
|
215
|
+
... "yellow",
|
216
|
+
... "green",
|
217
|
+
... "blue",
|
218
|
+
... "indigo",
|
219
|
+
... "violet",
|
220
|
+
... ],
|
221
|
+
... )
|
213
222
|
>>> st.write("My favorite color is", color)
|
214
223
|
|
215
224
|
And here's an example of a range select slider:
|
@@ -218,8 +227,17 @@ class SelectSliderMixin:
|
|
218
227
|
>>>
|
219
228
|
>>> start_color, end_color = st.select_slider(
|
220
229
|
... "Select a range of color wavelength",
|
221
|
-
... options=[
|
222
|
-
...
|
230
|
+
... options=[
|
231
|
+
... "red",
|
232
|
+
... "orange",
|
233
|
+
... "yellow",
|
234
|
+
... "green",
|
235
|
+
... "blue",
|
236
|
+
... "indigo",
|
237
|
+
... "violet",
|
238
|
+
... ],
|
239
|
+
... value=("red", "blue"),
|
240
|
+
... )
|
223
241
|
>>> st.write("You selected wavelengths between", start_color, "and", end_color)
|
224
242
|
|
225
243
|
.. output::
|
@@ -172,7 +172,8 @@ class SelectboxMixin:
|
|
172
172
|
>>>
|
173
173
|
>>> option = st.selectbox(
|
174
174
|
... "How would you like to be contacted?",
|
175
|
-
... ("Email", "Home phone", "Mobile phone")
|
175
|
+
... ("Email", "Home phone", "Mobile phone"),
|
176
|
+
... )
|
176
177
|
>>>
|
177
178
|
>>> st.write("You selected:", option)
|
178
179
|
|
@@ -185,10 +186,10 @@ class SelectboxMixin:
|
|
185
186
|
>>> import streamlit as st
|
186
187
|
>>>
|
187
188
|
>>> option = st.selectbox(
|
188
|
-
...
|
189
|
-
...
|
190
|
-
...
|
191
|
-
...
|
189
|
+
... "How would you like to be contacted?",
|
190
|
+
... ("Email", "Home phone", "Mobile phone"),
|
191
|
+
... index=None,
|
192
|
+
... placeholder="Select contact method...",
|
192
193
|
... )
|
193
194
|
>>>
|
194
195
|
>>> st.write("You selected:", option)
|
@@ -303,9 +303,7 @@ class SliderMixin:
|
|
303
303
|
|
304
304
|
>>> import streamlit as st
|
305
305
|
>>>
|
306
|
-
>>> values = st.slider(
|
307
|
-
... "Select a range of values",
|
308
|
-
... 0.0, 100.0, (25.0, 75.0))
|
306
|
+
>>> values = st.slider("Select a range of values", 0.0, 100.0, (25.0, 75.0))
|
309
307
|
>>> st.write("Values:", values)
|
310
308
|
|
311
309
|
This is a range time slider:
|
@@ -314,8 +312,8 @@ class SliderMixin:
|
|
314
312
|
>>> from datetime import time
|
315
313
|
>>>
|
316
314
|
>>> appointment = st.slider(
|
317
|
-
... "Schedule your appointment:",
|
318
|
-
...
|
315
|
+
... "Schedule your appointment:", value=(time(11, 30), time(12, 45))
|
316
|
+
... )
|
319
317
|
>>> st.write("You're scheduled for:", appointment)
|
320
318
|
|
321
319
|
Finally, a datetime slider:
|
@@ -326,7 +324,8 @@ class SliderMixin:
|
|
326
324
|
>>> start_time = st.slider(
|
327
325
|
... "When do you start?",
|
328
326
|
... value=datetime(2020, 1, 1, 9, 30),
|
329
|
-
... format="MM/DD/YY - hh:mm"
|
327
|
+
... format="MM/DD/YY - hh:mm",
|
328
|
+
... )
|
330
329
|
>>> st.write("Start time:", start_time)
|
331
330
|
|
332
331
|
.. output::
|
@@ -488,7 +488,7 @@ class TextWidgetsMixin:
|
|
488
488
|
... "was the epoch of incredulity, it was the season of Light, it was the "
|
489
489
|
... "season of Darkness, it was the spring of hope, it was the winter of "
|
490
490
|
... "despair, (...)",
|
491
|
-
...
|
491
|
+
... )
|
492
492
|
>>>
|
493
493
|
>>> st.write(f"You wrote {len(txt)} characters.")
|
494
494
|
|
streamlit/elements/write.py
CHANGED
@@ -302,7 +302,7 @@ class WriteMixin:
|
|
302
302
|
|
303
303
|
>>> import streamlit as st
|
304
304
|
>>>
|
305
|
-
>>> st.write(
|
305
|
+
>>> st.write("Hello, *World!* :sunglasses:")
|
306
306
|
|
307
307
|
.. output::
|
308
308
|
https://doc-write1.streamlit.app/
|
@@ -315,10 +315,14 @@ class WriteMixin:
|
|
315
315
|
>>> import pandas as pd
|
316
316
|
>>>
|
317
317
|
>>> st.write(1234)
|
318
|
-
>>> st.write(
|
319
|
-
...
|
320
|
-
...
|
321
|
-
...
|
318
|
+
>>> st.write(
|
319
|
+
... pd.DataFrame(
|
320
|
+
... {
|
321
|
+
... "first column": [1, 2, 3, 4],
|
322
|
+
... "second column": [10, 20, 30, 40],
|
323
|
+
... }
|
324
|
+
... )
|
325
|
+
... )
|
322
326
|
|
323
327
|
.. output::
|
324
328
|
https://doc-write2.streamlit.app/
|
@@ -328,8 +332,8 @@ class WriteMixin:
|
|
328
332
|
|
329
333
|
>>> import streamlit as st
|
330
334
|
>>>
|
331
|
-
>>> st.write(
|
332
|
-
>>> st.write(
|
335
|
+
>>> st.write("1 + 1 = ", 2)
|
336
|
+
>>> st.write("Below is a DataFrame:", data_frame, "Above is a dataframe.")
|
333
337
|
|
334
338
|
.. output::
|
335
339
|
https://doc-write3.streamlit.app/
|
@@ -342,12 +346,12 @@ class WriteMixin:
|
|
342
346
|
>>> import numpy as np
|
343
347
|
>>> import altair as alt
|
344
348
|
>>>
|
345
|
-
>>> df = pd.DataFrame(
|
346
|
-
|
347
|
-
...
|
348
|
-
...
|
349
|
-
|
350
|
-
...
|
349
|
+
>>> df = pd.DataFrame(np.random.randn(200, 3), columns=["a", "b", "c"])
|
350
|
+
>>> c = (
|
351
|
+
... alt.Chart(df)
|
352
|
+
... .mark_circle()
|
353
|
+
... .encode(x="a", y="b", size="c", color="c", tooltip=["a", "b", "c"])
|
354
|
+
... )
|
351
355
|
>>>
|
352
356
|
>>> st.write(c)
|
353
357
|
|
@@ -467,7 +467,7 @@ class CacheDataAPI:
|
|
467
467
|
... def fetch_and_clean_data(url):
|
468
468
|
... # Fetch data from URL here, and then clean it up.
|
469
469
|
... return data
|
470
|
-
|
470
|
+
>>>
|
471
471
|
>>> d1 = fetch_and_clean_data(DATA_URL_1)
|
472
472
|
>>> # Actually executes the function, since this is the first time it was
|
473
473
|
>>> # encountered.
|
@@ -498,7 +498,7 @@ class CacheDataAPI:
|
|
498
498
|
... def fetch_and_clean_data(_db_connection, num_rows):
|
499
499
|
... # Fetch data from _db_connection here, and then clean it up.
|
500
500
|
... return data
|
501
|
-
|
501
|
+
>>>
|
502
502
|
>>> connection = make_database_connection()
|
503
503
|
>>> d1 = fetch_and_clean_data(connection, num_rows=10)
|
504
504
|
>>> # Actually executes the function, since this is the first time it was
|
@@ -518,7 +518,7 @@ class CacheDataAPI:
|
|
518
518
|
... def fetch_and_clean_data(_db_connection, num_rows):
|
519
519
|
... # Fetch data from _db_connection here, and then clean it up.
|
520
520
|
... return data
|
521
|
-
|
521
|
+
>>>
|
522
522
|
>>> fetch_and_clean_data.clear(_db_connection, 50)
|
523
523
|
>>> # Clear the cached entry for the arguments provided.
|
524
524
|
>>>
|
@@ -339,7 +339,7 @@ class CacheResourceAPI:
|
|
339
339
|
... def get_database_session(url):
|
340
340
|
... # Create a database session object that points to the URL.
|
341
341
|
... return session
|
342
|
-
|
342
|
+
>>>
|
343
343
|
>>> s1 = get_database_session(SESSION_URL_1)
|
344
344
|
>>> # Actually executes the function, since this is the first time it was
|
345
345
|
>>> # encountered.
|
@@ -361,7 +361,7 @@ class CacheResourceAPI:
|
|
361
361
|
... def get_database_session(_sessionmaker, url):
|
362
362
|
... # Create a database connection object that points to the URL.
|
363
363
|
... return connection
|
364
|
-
|
364
|
+
>>>
|
365
365
|
>>> s1 = get_database_session(create_sessionmaker(), DATA_URL_1)
|
366
366
|
>>> # Actually executes the function, since this is the first time it was
|
367
367
|
>>> # encountered.
|
@@ -379,7 +379,7 @@ class CacheResourceAPI:
|
|
379
379
|
... def get_database_session(_sessionmaker, url):
|
380
380
|
... # Create a database connection object that points to the URL.
|
381
381
|
... return connection
|
382
|
-
|
382
|
+
>>>
|
383
383
|
>>> fetch_and_clean_data.clear(_sessionmaker, "https://streamlit.io/")
|
384
384
|
>>> # Clear the cached entry for the arguments provided.
|
385
385
|
>>>
|
@@ -90,7 +90,7 @@ def cache(
|
|
90
90
|
... def fetch_and_clean_data(url):
|
91
91
|
... # Fetch data from URL here, and then clean it up.
|
92
92
|
... return data
|
93
|
-
|
93
|
+
>>>
|
94
94
|
>>> d1 = fetch_and_clean_data(DATA_URL_1)
|
95
95
|
>>> # Actually executes the function, since this is the first time it was
|
96
96
|
>>> # encountered.
|
@@ -252,21 +252,27 @@ def connection_factory(
|
|
252
252
|
file.
|
253
253
|
|
254
254
|
>>> import streamlit as st
|
255
|
-
>>> conn = st.connection("sql")
|
255
|
+
>>> conn = st.connection("sql") # [connections.sql] section in secrets.toml.
|
256
256
|
|
257
257
|
Creating a SQLConnection with a custom name requires you to explicitly specify the
|
258
258
|
type. If type is not passed as a kwarg, it must be set in the appropriate section of
|
259
259
|
``secrets.toml``.
|
260
260
|
|
261
261
|
>>> import streamlit as st
|
262
|
-
>>> conn1 = st.connection(
|
263
|
-
|
262
|
+
>>> conn1 = st.connection(
|
263
|
+
... "my_sql_connection", type="sql"
|
264
|
+
... ) # Config section defined in [connections.my_sql_connection].
|
265
|
+
>>> conn2 = st.connection(
|
266
|
+
... "my_other_sql_connection"
|
267
|
+
... ) # type must be set in [connections.my_other_sql_connection].
|
264
268
|
|
265
269
|
Passing the full module path to the connection class that you want to use can be
|
266
270
|
useful, especially when working with a custom connection:
|
267
271
|
|
268
272
|
>>> import streamlit as st
|
269
|
-
>>> conn = st.connection(
|
273
|
+
>>> conn = st.connection(
|
274
|
+
... "my_sql_connection", type="streamlit.connections.SQLConnection"
|
275
|
+
... )
|
270
276
|
|
271
277
|
Finally, you can pass the connection class to use directly to this function. Doing
|
272
278
|
so allows static type checking tools such as ``mypy`` to infer the exact return
|