streamlit-nightly 1.39.1.dev20241030__py2.py3-none-any.whl → 1.39.1.dev20241101__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. streamlit/commands/logo.py +3 -3
  2. streamlit/commands/navigation.py +48 -3
  3. streamlit/commands/page_config.py +3 -3
  4. streamlit/elements/image.py +26 -441
  5. streamlit/elements/layouts.py +12 -7
  6. streamlit/elements/lib/image_utils.py +433 -0
  7. streamlit/elements/markdown.py +6 -0
  8. streamlit/elements/metric.py +8 -5
  9. streamlit/elements/progress.py +2 -1
  10. streamlit/elements/pyplot.py +3 -5
  11. streamlit/elements/text.py +1 -1
  12. streamlit/elements/widgets/audio_input.py +12 -11
  13. streamlit/elements/widgets/button.py +20 -16
  14. streamlit/elements/widgets/button_group.py +146 -121
  15. streamlit/elements/widgets/camera_input.py +13 -11
  16. streamlit/elements/widgets/chat.py +2 -2
  17. streamlit/elements/widgets/checkbox.py +30 -24
  18. streamlit/elements/widgets/color_picker.py +15 -13
  19. streamlit/elements/widgets/file_uploader.py +12 -12
  20. streamlit/elements/widgets/multiselect.py +33 -31
  21. streamlit/elements/widgets/number_input.py +15 -12
  22. streamlit/elements/widgets/radio.py +15 -12
  23. streamlit/elements/widgets/select_slider.py +15 -12
  24. streamlit/elements/widgets/selectbox.py +19 -14
  25. streamlit/elements/widgets/slider.py +15 -12
  26. streamlit/elements/widgets/text_widgets.py +33 -27
  27. streamlit/elements/widgets/time_widgets.py +33 -25
  28. streamlit/hello/{Animation_Demo.py → animation_demo.py} +9 -10
  29. streamlit/hello/{Dataframe_Demo.py → dataframe_demo.py} +9 -15
  30. streamlit/hello/{Hello.py → hello.py} +7 -12
  31. streamlit/hello/{Mapping_Demo.py → mapping_demo.py} +10 -13
  32. streamlit/hello/{Plotting_Demo.py → plotting_demo.py} +9 -10
  33. streamlit/hello/streamlit_app.py +24 -6
  34. streamlit/proto/Image_pb2.pyi +1 -1
  35. streamlit/web/server/server.py +6 -1
  36. {streamlit_nightly-1.39.1.dev20241030.dist-info → streamlit_nightly-1.39.1.dev20241101.dist-info}/METADATA +1 -1
  37. {streamlit_nightly-1.39.1.dev20241030.dist-info → streamlit_nightly-1.39.1.dev20241101.dist-info}/RECORD +41 -40
  38. {streamlit_nightly-1.39.1.dev20241030.data → streamlit_nightly-1.39.1.dev20241101.data}/scripts/streamlit.cmd +0 -0
  39. {streamlit_nightly-1.39.1.dev20241030.dist-info → streamlit_nightly-1.39.1.dev20241101.dist-info}/WHEEL +0 -0
  40. {streamlit_nightly-1.39.1.dev20241030.dist-info → streamlit_nightly-1.39.1.dev20241101.dist-info}/entry_points.txt +0 -0
  41. {streamlit_nightly-1.39.1.dev20241030.dist-info → streamlit_nightly-1.39.1.dev20241101.dist-info}/top_level.txt +0 -0
@@ -369,7 +369,9 @@ class LayoutsMixin:
369
369
  Creates a tab for each string in the list. The first tab is selected
370
370
  by default. The string is used as the name of the tab and can
371
371
  optionally contain GitHub-flavored Markdown of the following types:
372
- Bold, Italics, Strikethroughs, Inline Code, and Links.
372
+ Bold, Italics, Strikethroughs, Inline Code, Links, and Images.
373
+ Images display like icons, with a max height equal to the font
374
+ height.
373
375
 
374
376
  Unsupported Markdown elements are unwrapped so only their children
375
377
  (text contents) render. Display unsupported elements as literal
@@ -476,7 +478,8 @@ class LayoutsMixin:
476
478
  label : str
477
479
  A string to use as the header for the expander. The label can optionally
478
480
  contain GitHub-flavored Markdown of the following types: Bold, Italics,
479
- Strikethroughs, Inline Code, and Links.
481
+ Strikethroughs, Inline Code, Links, and Images. Images display like
482
+ icons, with a max height equal to the font height.
480
483
 
481
484
  Unsupported Markdown elements are unwrapped so only their children
482
485
  (text contents) render. Display unsupported elements as literal
@@ -595,8 +598,9 @@ class LayoutsMixin:
595
598
  label : str
596
599
  The label of the button that opens the popover container.
597
600
  The label can optionally contain GitHub-flavored Markdown of the
598
- following types: Bold, Italics, Strikethroughs, Inline Code, and
599
- Links.
601
+ following types: Bold, Italics, Strikethroughs, Inline Code, Links,
602
+ and Images. Images display like icons, with a max height equal to
603
+ the font height.
600
604
 
601
605
  Unsupported Markdown elements are unwrapped so only their children
602
606
  (text contents) render. Display unsupported elements as literal
@@ -631,8 +635,8 @@ class LayoutsMixin:
631
635
  font library.
632
636
 
633
637
  disabled : bool
634
- An optional boolean, which disables the popover button if set to
635
- True. The default is False.
638
+ An optional boolean that disables the popover button if set to
639
+ ``True``. The default is ``False``.
636
640
 
637
641
  use_container_width : bool
638
642
  Whether to expand the button's width to fill its parent container.
@@ -729,7 +733,8 @@ class LayoutsMixin:
729
733
  label : str
730
734
  The initial label of the status container. The label can optionally
731
735
  contain GitHub-flavored Markdown of the following types: Bold, Italics,
732
- Strikethroughs, Inline Code, and Links.
736
+ Strikethroughs, Inline Code, Links, and Images. Images display like
737
+ icons, with a max height equal to the font height.
733
738
 
734
739
  Unsupported Markdown elements are unwrapped so only their children
735
740
  (text contents) render. Display unsupported elements as literal
@@ -0,0 +1,433 @@
1
+ # Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import io
18
+ import os
19
+ import re
20
+ from enum import IntEnum
21
+ from typing import TYPE_CHECKING, Final, Literal, Sequence, Union, cast
22
+
23
+ from typing_extensions import TypeAlias
24
+
25
+ from streamlit import runtime, url_util
26
+ from streamlit.errors import StreamlitAPIException
27
+ from streamlit.runtime import caching
28
+ from streamlit.type_util import NumpyShape
29
+
30
+ if TYPE_CHECKING:
31
+ from typing import Any
32
+
33
+ import numpy.typing as npt
34
+ from PIL import GifImagePlugin, Image, ImageFile
35
+
36
+ from streamlit.proto.Image_pb2 import ImageList as ImageListProto
37
+
38
+ PILImage: TypeAlias = Union[
39
+ "ImageFile.ImageFile", "Image.Image", "GifImagePlugin.GifImageFile"
40
+ ]
41
+ AtomicImage: TypeAlias = Union[PILImage, "npt.NDArray[Any]", io.BytesIO, str, bytes]
42
+
43
+ Channels: TypeAlias = Literal["RGB", "BGR"]
44
+ ImageFormat: TypeAlias = Literal["JPEG", "PNG", "GIF"]
45
+ ImageFormatOrAuto: TypeAlias = Literal[ImageFormat, "auto"]
46
+ ImageOrImageList: TypeAlias = Union[AtomicImage, Sequence[AtomicImage]]
47
+
48
+ # This constant is related to the frontend maximum content width specified
49
+ # in App.jsx main container
50
+ # 730 is the max width of element-container in the frontend, and 2x is for high
51
+ # DPI.
52
+ MAXIMUM_CONTENT_WIDTH: Final[int] = 2 * 730
53
+
54
+
55
+ # @see Image.proto
56
+ # @see WidthBehavior on the frontend
57
+ class WidthBehavior(IntEnum):
58
+ """
59
+ Special values that are recognized by the frontend and allow us to change the
60
+ behavior of the displayed image.
61
+ """
62
+
63
+ ORIGINAL = -1
64
+ COLUMN = -2
65
+ AUTO = -3
66
+ MIN_IMAGE_OR_CONTAINER = -4
67
+ MAX_IMAGE_OR_CONTAINER = -5
68
+
69
+
70
+ WidthBehavior.ORIGINAL.__doc__ = """Display the image at its original width"""
71
+ WidthBehavior.COLUMN.__doc__ = (
72
+ """Display the image at the width of the column it's in."""
73
+ )
74
+ WidthBehavior.AUTO.__doc__ = """Display the image at its original width, unless it
75
+ would exceed the width of its column in which case clamp it to
76
+ its column width"""
77
+
78
+
79
+ def _image_may_have_alpha_channel(image: PILImage) -> bool:
80
+ return image.mode in ("RGBA", "LA", "P")
81
+
82
+
83
+ def _image_is_gif(image: PILImage) -> bool:
84
+ return image.format == "GIF"
85
+
86
+
87
+ def _validate_image_format_string(
88
+ image_data: bytes | PILImage, format: str
89
+ ) -> ImageFormat:
90
+ """Return either "JPEG", "PNG", or "GIF", based on the input `format` string.
91
+ - If `format` is "JPEG" or "JPG" (or any capitalization thereof), return "JPEG"
92
+ - If `format` is "PNG" (or any capitalization thereof), return "PNG"
93
+ - For all other strings, return "PNG" if the image has an alpha channel,
94
+ "GIF" if the image is a GIF, and "JPEG" otherwise.
95
+ """
96
+ format = format.upper()
97
+ if format in {"JPEG", "PNG"}:
98
+ return cast(ImageFormat, format)
99
+
100
+ # We are forgiving on the spelling of JPEG
101
+ if format == "JPG":
102
+ return "JPEG"
103
+
104
+ pil_image: PILImage
105
+ if isinstance(image_data, bytes):
106
+ from PIL import Image
107
+
108
+ pil_image = Image.open(io.BytesIO(image_data))
109
+ else:
110
+ pil_image = image_data
111
+
112
+ if _image_is_gif(pil_image):
113
+ return "GIF"
114
+
115
+ if _image_may_have_alpha_channel(pil_image):
116
+ return "PNG"
117
+
118
+ return "JPEG"
119
+
120
+
121
+ def _PIL_to_bytes(
122
+ image: PILImage,
123
+ format: ImageFormat = "JPEG",
124
+ quality: int = 100,
125
+ ) -> bytes:
126
+ """Convert a PIL image to bytes."""
127
+ tmp = io.BytesIO()
128
+
129
+ # User must have specified JPEG, so we must convert it
130
+ if format == "JPEG" and _image_may_have_alpha_channel(image):
131
+ image = image.convert("RGB")
132
+
133
+ image.save(tmp, format=format, quality=quality)
134
+
135
+ return tmp.getvalue()
136
+
137
+
138
+ def _BytesIO_to_bytes(data: io.BytesIO) -> bytes:
139
+ data.seek(0)
140
+ return data.getvalue()
141
+
142
+
143
+ def _np_array_to_bytes(array: npt.NDArray[Any], output_format: str = "JPEG") -> bytes:
144
+ import numpy as np
145
+ from PIL import Image
146
+
147
+ img = Image.fromarray(array.astype(np.uint8))
148
+ format = _validate_image_format_string(img, output_format)
149
+
150
+ return _PIL_to_bytes(img, format)
151
+
152
+
153
+ def _verify_np_shape(array: npt.NDArray[Any]) -> npt.NDArray[Any]:
154
+ shape: NumpyShape = array.shape
155
+ if len(shape) not in (2, 3):
156
+ raise StreamlitAPIException("Numpy shape has to be of length 2 or 3.")
157
+ if len(shape) == 3 and shape[-1] not in (1, 3, 4):
158
+ raise StreamlitAPIException(
159
+ "Channel can only be 1, 3, or 4 got %d. Shape is %s"
160
+ % (shape[-1], str(shape))
161
+ )
162
+
163
+ # If there's only one channel, convert is to x, y
164
+ if len(shape) == 3 and shape[-1] == 1:
165
+ array = array[:, :, 0]
166
+
167
+ return array
168
+
169
+
170
+ def _get_image_format_mimetype(image_format: ImageFormat) -> str:
171
+ """Get the mimetype string for the given ImageFormat."""
172
+ return f"image/{image_format.lower()}"
173
+
174
+
175
+ def _ensure_image_size_and_format(
176
+ image_data: bytes, width: int, image_format: ImageFormat
177
+ ) -> bytes:
178
+ """Resize an image if it exceeds the given width, or if exceeds
179
+ MAXIMUM_CONTENT_WIDTH. Ensure the image's format corresponds to the given
180
+ ImageFormat. Return the (possibly resized and reformatted) image bytes.
181
+ """
182
+ from PIL import Image
183
+
184
+ pil_image: PILImage = Image.open(io.BytesIO(image_data))
185
+ actual_width, actual_height = pil_image.size
186
+
187
+ if width < 0 and actual_width > MAXIMUM_CONTENT_WIDTH:
188
+ width = MAXIMUM_CONTENT_WIDTH
189
+
190
+ if width > 0 and actual_width > width:
191
+ # We need to resize the image.
192
+ new_height = int(1.0 * actual_height * width / actual_width)
193
+ # pillow reexports Image.Resampling.BILINEAR as Image.BILINEAR for backwards
194
+ # compatibility reasons, so we use the reexport to support older pillow
195
+ # versions. The types don't seem to reflect this, though, hence the type: ignore
196
+ # below.
197
+ pil_image = pil_image.resize((width, new_height), resample=Image.BILINEAR) # type: ignore[attr-defined]
198
+ return _PIL_to_bytes(pil_image, format=image_format, quality=90)
199
+
200
+ if pil_image.format != image_format:
201
+ # We need to reformat the image.
202
+ return _PIL_to_bytes(pil_image, format=image_format, quality=90)
203
+
204
+ # No resizing or reformatting necessary - return the original bytes.
205
+ return image_data
206
+
207
+
208
+ def _clip_image(image: npt.NDArray[Any], clamp: bool) -> npt.NDArray[Any]:
209
+ import numpy as np
210
+
211
+ data = image
212
+ if issubclass(image.dtype.type, np.floating):
213
+ if clamp:
214
+ data = np.clip(image, 0, 1.0)
215
+ else:
216
+ if np.amin(image) < 0.0 or np.amax(image) > 1.0:
217
+ raise RuntimeError("Data is outside [0.0, 1.0] and clamp is not set.")
218
+ data = data * 255
219
+ else:
220
+ if clamp:
221
+ data = np.clip(image, 0, 255)
222
+ else:
223
+ if np.amin(image) < 0 or np.amax(image) > 255:
224
+ raise RuntimeError("Data is outside [0, 255] and clamp is not set.")
225
+ return data
226
+
227
+
228
+ def image_to_url(
229
+ image: AtomicImage,
230
+ width: int,
231
+ clamp: bool,
232
+ channels: Channels,
233
+ output_format: ImageFormatOrAuto,
234
+ image_id: str,
235
+ ) -> str:
236
+ """Return a URL that an image can be served from.
237
+ If `image` is already a URL, return it unmodified.
238
+ Otherwise, add the image to the MediaFileManager and return the URL.
239
+ (When running in "raw" mode, we won't actually load data into the
240
+ MediaFileManager, and we'll return an empty URL.)
241
+ """
242
+ import numpy as np
243
+ from PIL import Image, ImageFile
244
+
245
+ image_data: bytes
246
+
247
+ # Strings
248
+ if isinstance(image, str):
249
+ if not os.path.isfile(image) and url_util.is_url(
250
+ image, allowed_schemas=("http", "https", "data")
251
+ ):
252
+ # If it's a url, return it directly.
253
+ return image
254
+
255
+ if image.endswith(".svg") and os.path.isfile(image):
256
+ # Unpack local SVG image file to an SVG string
257
+ with open(image) as textfile:
258
+ image = textfile.read()
259
+
260
+ # Following regex allows svg image files to start either via a "<?xml...>" tag
261
+ # eventually followed by a "<svg...>" tag or directly starting with a "<svg>" tag
262
+ if re.search(r"(^\s?(<\?xml[\s\S]*<svg\s)|^\s?<svg\s|^\s?<svg>\s)", image):
263
+ if "xmlns" not in image:
264
+ # The xmlns attribute is required for SVGs to render in an img tag.
265
+ # If it's not present, we add to the first SVG tag:
266
+ image = image.replace(
267
+ "<svg", '<svg xmlns="http://www.w3.org/2000/svg" ', 1
268
+ )
269
+ # Convert to base64 to prevent issues with encoding:
270
+ import base64
271
+
272
+ image_b64_encoded = base64.b64encode(image.encode("utf-8")).decode("utf-8")
273
+ # Return SVG as data URI:
274
+ return f"data:image/svg+xml;base64,{image_b64_encoded}"
275
+
276
+ # Otherwise, try to open it as a file.
277
+ try:
278
+ with open(image, "rb") as f:
279
+ image_data = f.read()
280
+ except Exception:
281
+ # When we aren't able to open the image file, we still pass the path to
282
+ # the MediaFileManager - its storage backend may have access to files
283
+ # that Streamlit does not.
284
+ import mimetypes
285
+
286
+ mimetype, _ = mimetypes.guess_type(image)
287
+ if mimetype is None:
288
+ mimetype = "application/octet-stream"
289
+
290
+ url = runtime.get_instance().media_file_mgr.add(image, mimetype, image_id)
291
+ caching.save_media_data(image, mimetype, image_id)
292
+ return url
293
+
294
+ # PIL Images
295
+ elif isinstance(image, (ImageFile.ImageFile, Image.Image)):
296
+ format = _validate_image_format_string(image, output_format)
297
+ image_data = _PIL_to_bytes(image, format)
298
+
299
+ # BytesIO
300
+ # Note: This doesn't support SVG. We could convert to png (cairosvg.svg2png)
301
+ # or just decode BytesIO to string and handle that way.
302
+ elif isinstance(image, io.BytesIO):
303
+ image_data = _BytesIO_to_bytes(image)
304
+
305
+ # Numpy Arrays (ie opencv)
306
+ elif isinstance(image, np.ndarray):
307
+ image = _clip_image(_verify_np_shape(image), clamp)
308
+
309
+ if channels == "BGR":
310
+ if len(cast(NumpyShape, image.shape)) == 3:
311
+ image = image[:, :, [2, 1, 0]]
312
+ else:
313
+ raise StreamlitAPIException(
314
+ 'When using `channels="BGR"`, the input image should '
315
+ "have exactly 3 color channels"
316
+ )
317
+
318
+ image_data = _np_array_to_bytes(array=image, output_format=output_format)
319
+
320
+ # Raw bytes
321
+ else:
322
+ image_data = image
323
+
324
+ # Determine the image's format, resize it, and get its mimetype
325
+ image_format = _validate_image_format_string(image_data, output_format)
326
+ image_data = _ensure_image_size_and_format(image_data, width, image_format)
327
+ mimetype = _get_image_format_mimetype(image_format)
328
+
329
+ if runtime.exists():
330
+ url = runtime.get_instance().media_file_mgr.add(image_data, mimetype, image_id)
331
+ caching.save_media_data(image_data, mimetype, image_id)
332
+ return url
333
+ else:
334
+ # When running in "raw mode", we can't access the MediaFileManager.
335
+ return ""
336
+
337
+
338
+ def _4d_to_list_3d(array: npt.NDArray[Any]) -> list[npt.NDArray[Any]]:
339
+ return [array[i, :, :, :] for i in range(0, array.shape[0])]
340
+
341
+
342
+ def marshall_images(
343
+ coordinates: str,
344
+ image: ImageOrImageList,
345
+ caption: str | npt.NDArray[Any] | list[str] | None,
346
+ width: int | WidthBehavior,
347
+ proto_imgs: ImageListProto,
348
+ clamp: bool,
349
+ channels: Channels = "RGB",
350
+ output_format: ImageFormatOrAuto = "auto",
351
+ ) -> None:
352
+ """Fill an ImageListProto with a list of images and their captions.
353
+ The images will be resized and reformatted as necessary.
354
+ Parameters
355
+ ----------
356
+ coordinates
357
+ A string indentifying the images' location in the frontend.
358
+ image
359
+ The image or images to include in the ImageListProto.
360
+ caption
361
+ Image caption. If displaying multiple images, caption should be a
362
+ list of captions (one for each image).
363
+ width
364
+ The desired width of the image or images. This parameter will be
365
+ passed to the frontend.
366
+ Positive values set the image width explicitly.
367
+ Negative values has some special. For details, see: `WidthBehaviour`
368
+ proto_imgs
369
+ The ImageListProto to fill in.
370
+ clamp
371
+ Clamp image pixel values to a valid range ([0-255] per channel).
372
+ This is only meaningful for byte array images; the parameter is
373
+ ignored for image URLs. If this is not set, and an image has an
374
+ out-of-range value, an error will be thrown.
375
+ channels
376
+ If image is an nd.array, this parameter denotes the format used to
377
+ represent color information. Defaults to 'RGB', meaning
378
+ `image[:, :, 0]` is the red channel, `image[:, :, 1]` is green, and
379
+ `image[:, :, 2]` is blue. For images coming from libraries like
380
+ OpenCV you should set this to 'BGR', instead.
381
+ output_format
382
+ This parameter specifies the format to use when transferring the
383
+ image data. Photos should use the JPEG format for lossy compression
384
+ while diagrams should use the PNG format for lossless compression.
385
+ Defaults to 'auto' which identifies the compression type based
386
+ on the type and format of the image argument.
387
+ """
388
+ import numpy as np
389
+
390
+ channels = cast(Channels, channels.upper())
391
+
392
+ # Turn single image and caption into one element list.
393
+ images: Sequence[AtomicImage]
394
+ if isinstance(image, (list, set, tuple)):
395
+ images = list(image)
396
+ elif isinstance(image, np.ndarray) and len(cast(NumpyShape, image.shape)) == 4:
397
+ images = _4d_to_list_3d(image)
398
+ else:
399
+ images = [image] # type: ignore
400
+
401
+ if isinstance(caption, list):
402
+ captions: Sequence[str | None] = caption
403
+ elif isinstance(caption, str):
404
+ captions = [caption]
405
+ elif isinstance(caption, np.ndarray) and len(cast(NumpyShape, caption.shape)) == 1:
406
+ captions = caption.tolist()
407
+ elif caption is None:
408
+ captions = [None] * len(images)
409
+ else:
410
+ captions = [str(caption)]
411
+
412
+ assert isinstance(
413
+ captions, list
414
+ ), "If image is a list then caption should be as well"
415
+ assert len(captions) == len(images), "Cannot pair %d captions with %d images." % (
416
+ len(captions),
417
+ len(images),
418
+ )
419
+
420
+ proto_imgs.width = int(width)
421
+ # Each image in an image list needs to be kept track of at its own coordinates.
422
+ for coord_suffix, (image, caption) in enumerate(zip(images, captions)):
423
+ proto_img = proto_imgs.imgs.add()
424
+ if caption is not None:
425
+ proto_img.caption = str(caption)
426
+
427
+ # We use the index of the image in the input image list to identify this image inside
428
+ # MediaFileManager. For this, we just add the index to the image's "coordinates".
429
+ image_id = "%s-%i" % (coordinates, coord_suffix)
430
+
431
+ proto_img.url = image_to_url(
432
+ image, width, clamp, channels, output_format, image_id
433
+ )
@@ -52,6 +52,12 @@ class MarkdownMixin:
52
52
  For a list of all supported codes,
53
53
  see https://share.streamlit.io/streamlit/emoji-shortcodes.
54
54
 
55
+ * Streamlit logo shortcode. Use ``:streamlit:`` to add a little
56
+ Streamlit flair to your text.
57
+
58
+ * A limited set of typographical symbols. ``"<- -> <-> -- >= <= ~="``
59
+ becomes "← → ↔ — ≥ ≤ ≈" when parsed as Markdown.
60
+
55
61
  * Google Material Symbols (rounded style), using the syntax
56
62
  ``:material/icon_name:``, where "icon_name" is the name of the
57
63
  icon in snake case. For a complete list of icons, see Google's
@@ -70,7 +70,8 @@ class MetricMixin:
70
70
  label : str
71
71
  The header or title for the metric. The label can optionally
72
72
  contain GitHub-flavored Markdown of the following types: Bold, Italics,
73
- Strikethroughs, Inline Code, and Links.
73
+ Strikethroughs, Inline Code, Links, and Images. Images display like
74
+ icons, with a max height equal to the font height.
74
75
 
75
76
  Unsupported Markdown elements are unwrapped so only their children
76
77
  (text contents) render. Display unsupported elements as literal
@@ -102,12 +103,14 @@ class MetricMixin:
102
103
 
103
104
  help : str
104
105
  An optional tooltip that gets displayed next to the metric label.
106
+ Streamlit only displays the tooltip when
107
+ ``label_visibility="visible"``.
105
108
 
106
109
  label_visibility : "visible", "hidden", or "collapsed"
107
- The visibility of the label. If "hidden", the label doesn't show but there
108
- is still empty space for it (equivalent to label="").
109
- If "collapsed", both the label and the space are removed. Default is
110
- "visible".
110
+ The visibility of the label. The default is ``"visible"``. If this
111
+ is ``"hidden"``, Streamlit displays an empty spacer instead of the
112
+ label, which can help keep the widget alligned with other widgets.
113
+ If this is ``"collapsed"``, Streamlit displays no label or spacer.
111
114
 
112
115
  Example
113
116
  -------
@@ -105,7 +105,8 @@ class ProgressMixin:
105
105
  text : str or None
106
106
  A message to display above the progress bar. The text can optionally
107
107
  contain GitHub-flavored Markdown of the following types: Bold, Italics,
108
- Strikethroughs, Inline Code, and Links.
108
+ Strikethroughs, Inline Code, Links, and Images. Images display like
109
+ icons, with a max height equal to the font height.
109
110
 
110
111
  Unsupported Markdown elements are unwrapped so only their children
111
112
  (text contents) render. Display unsupported elements as literal
@@ -19,8 +19,8 @@ from __future__ import annotations
19
19
  import io
20
20
  from typing import TYPE_CHECKING, Any, cast
21
21
 
22
- import streamlit.elements.image as image_utils
23
22
  from streamlit.deprecation_util import show_deprecation_warning
23
+ from streamlit.elements.lib.image_utils import WidthBehavior, marshall_images
24
24
  from streamlit.proto.Image_pb2 import ImageList as ImageListProto
25
25
  from streamlit.runtime.metrics_util import gather_metrics
26
26
 
@@ -172,11 +172,9 @@ def marshall(
172
172
  image = io.BytesIO()
173
173
  fig.savefig(image, **kwargs)
174
174
  image_width = (
175
- image_utils.WidthBehaviour.COLUMN
176
- if use_container_width
177
- else image_utils.WidthBehaviour.ORIGINAL
175
+ WidthBehavior.COLUMN if use_container_width else WidthBehavior.ORIGINAL
178
176
  )
179
- image_utils.marshall_images(
177
+ marshall_images(
180
178
  coordinates=coordinates,
181
179
  image=image,
182
180
  caption=None,
@@ -52,7 +52,7 @@ class TextMixin:
52
52
  -------
53
53
  >>> import streamlit as st
54
54
  >>>
55
- >>> st.text("This is text/n[and more text](that's not a Markdown link).")
55
+ >>> st.text("This is text\\n[and more text](that's not a Markdown link).")
56
56
 
57
57
  .. output ::
58
58
  https://doc-text.streamlit.app/
@@ -107,8 +107,9 @@ class AudioInputMixin:
107
107
  label : str
108
108
  A short label explaining to the user what this widget is used for.
109
109
  The label can optionally contain GitHub-flavored Markdown of the
110
- following types: Bold, Italics, Strikethroughs, Inline Code, and
111
- Links.
110
+ following types: Bold, Italics, Strikethroughs, Inline Code, Links,
111
+ and Images. Images display like icons, with a max height equal to
112
+ the font height.
112
113
 
113
114
  Unsupported Markdown elements are unwrapped so only their children
114
115
  (text contents) render. Display unsupported elements as literal
@@ -118,9 +119,9 @@ class AudioInputMixin:
118
119
  See the ``body`` parameter of |st.markdown|_ for additional,
119
120
  supported Markdown directives.
120
121
 
121
- For accessibility reasons, you should never set an empty label (label="")
122
- but hide it with label_visibility if needed. In the future, we may disallow
123
- empty labels by raising an exception.
122
+ For accessibility reasons, you should never set an empty label, but
123
+ you can hide it with ``label_visibility`` if needed. In the future,
124
+ we may disallow empty labels by raising an exception.
124
125
 
125
126
  .. |st.markdown| replace:: ``st.markdown``
126
127
  .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown
@@ -144,14 +145,14 @@ class AudioInputMixin:
144
145
  An optional dict of kwargs to pass to the callback.
145
146
 
146
147
  disabled : bool
147
- An optional boolean, which disables the audio input if set to
148
- True. Default is False.
148
+ An optional boolean that disables the audio input if set to
149
+ ``True``. Default is ``False``.
149
150
 
150
151
  label_visibility : "visible", "hidden", or "collapsed"
151
- The visibility of the label. If "hidden", the label doesn't show but there
152
- is still empty space for it above the widget (equivalent to label="").
153
- If "collapsed", both the label and the space are removed. Default is
154
- "visible".
152
+ The visibility of the label. The default is ``"visible"``. If this
153
+ is ``"hidden"``, Streamlit displays an empty spacer instead of the
154
+ label, which can help keep the widget alligned with other widgets.
155
+ If this is ``"collapsed"``, Streamlit displays no label or spacer.
155
156
 
156
157
  Returns
157
158
  -------