diff --git a/lib/streamlit/commands/page_config.py b/lib/streamlit/commands/page_config.py index 8cf0bb96ab00..5ce313f5b47e 100644 --- a/lib/streamlit/commands/page_config.py +++ b/lib/streamlit/commands/page_config.py @@ -136,22 +136,50 @@ def set_page_config( page_title: str or None The page title, shown in the browser tab. If None, defaults to the filename of the script ("app.py" would show "app • Streamlit"). - page_icon : Anything supported by st.image or str or None - The page favicon. - Besides the types supported by `st.image` (like URLs or numpy arrays), - you can pass in an emoji as a string ("🦈") or a shortcode (":shark:"). - If you're feeling lucky, try "random" for a random emoji! - Emoji icons are courtesy of Twemoji and loaded from MaxCDN. + + page_icon : Anything supported by st.image, str, or None + The page favicon. If ``page_icon`` is ``None`` (default), the favicon + will be a monochrome Streamlit logo. + + In addition to the types supported by ``st.image`` (like URLs or numpy + arrays), the following strings are valid: + + * A single-character emoji. For example, you can set ``page_icon="🦈"``. + + * An emoji short code. For example, you can set ``page_icon=":shark:"``. + For a list of all supported codes, see + https://share.streamlit.io/streamlit/emoji-shortcodes. + + * The string literal, ``"random"``. You can set ``page_icon="random"`` + to set a random emoji from the supported list above. Emoji icons are + courtesy of Twemoji and loaded from MaxCDN. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. + + .. note:: + Colors are not supported for Material icons. When you use a + Material icon for favicon, it will be black, regardless of browser + theme. + layout: "centered" or "wide" How the page content should be laid out. Defaults to "centered", which constrains the elements into a centered column of fixed width; "wide" uses the entire screen. + initial_sidebar_state: "auto", "expanded", or "collapsed" How the sidebar should start out. Defaults to "auto", which hides the sidebar on small devices and shows it otherwise. "expanded" shows the sidebar initially; "collapsed" hides it. In most cases, you should just use "auto", otherwise the app will look bad when embedded and viewed on mobile. + menu_items: dict Configure the menu that appears on the top-right side of this app. The keys in this dict denote the menu item you'd like to configure: diff --git a/lib/streamlit/elements/alert.py b/lib/streamlit/elements/alert.py index 67811afe253e..39e57a0e066e 100644 --- a/lib/streamlit/elements/alert.py +++ b/lib/streamlit/elements/alert.py @@ -39,11 +39,22 @@ def error( ---------- body : str The error text to display. - icon : str or None - An optional argument that specifies an emoji to use as - the icon for the alert. Shortcodes are not allowed, please use a - single character instead. E.g. "🚨", "🔥", "🤖", etc. - Defaults to None, which means no icon is displayed. + icon : str, None + An optional emoji or icon to display next to the alert. If ``icon`` + is ``None`` (default), no icon is displayed. If ``icon`` is a + string, the following options are valid: + + * A single-character emoji. For example, you can set ``icon="🚨"`` + or ``icon="🔥"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Example ------- @@ -72,11 +83,22 @@ def warning( ---------- body : str The warning text to display. - icon : str or None - An optional argument that specifies an emoji to use as - the icon for the alert. Shortcodes are not allowed, please use a - single character instead. E.g. "🚨", "🔥", "🤖", etc. - Defaults to None, which means no icon is displayed. + icon : str, None + An optional emoji or icon to display next to the alert. If ``icon`` + is ``None`` (default), no icon is displayed. If ``icon`` is a + string, the following options are valid: + + * A single-character emoji. For example, you can set ``icon="🚨"`` + or ``icon="🔥"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Example ------- @@ -104,11 +126,22 @@ def info( ---------- body : str The info text to display. - icon : str or None - An optional argument that specifies an emoji to use as - the icon for the alert. Shortcodes are not allowed, please use a - single character instead. E.g. "🚨", "🔥", "🤖", etc. - Defaults to None, which means no icon is displayed. + icon : str, None + An optional emoji or icon to display next to the alert. If ``icon`` + is ``None`` (default), no icon is displayed. If ``icon`` is a + string, the following options are valid: + + * A single-character emoji. For example, you can set ``icon="🚨"`` + or ``icon="🔥"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Example ------- @@ -137,11 +170,22 @@ def success( ---------- body : str The success text to display. - icon : str or None - An optional argument that specifies an emoji to use as - the icon for the alert. Shortcodes are not allowed, please use a - single character instead. E.g. "🚨", "🔥", "🤖", etc. - Defaults to None, which means no icon is displayed. + icon : str, None + An optional emoji or icon to display next to the alert. If ``icon`` + is ``None`` (default), no icon is displayed. If ``icon`` is a + string, the following options are valid: + + * A single-character emoji. For example, you can set ``icon="🚨"`` + or ``icon="🔥"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Example ------- diff --git a/lib/streamlit/elements/dialog_decorator.py b/lib/streamlit/elements/dialog_decorator.py index 498f0f1c325b..54357dd68083 100644 --- a/lib/streamlit/elements/dialog_decorator.py +++ b/lib/streamlit/elements/dialog_decorator.py @@ -94,56 +94,81 @@ def dialog_decorator(title: F | None, *, width: DialogWidth = "small") -> F: def dialog_decorator( title: F | None | str = "", *, width: DialogWidth = "small" ) -> F | Callable[[F], F]: - r"""Decorate a function to mark it as a Streamlit dialog. When the decorated function is called, a dialog element is inserted with the function's body as the content. + """Function decorator to create a modal dialog. - The decorated function can hold multiple elements which are rendered inside of a modal when the decorated function is called. - The decorated function is using `st.experimental_fragment`, which means that interacting with elements inside of the dialog will - only re-run the dialog function. + A function decorated with ``@st.experimental_dialog`` becomes a dialog + function. When you call a dialog function, Streamlit inserts a modal dialog + into your app. Streamlit element commands called within the dialog function + render inside the modal dialog. - The decorated function can accept arguments that can be passed when it is called. + The dialog function can accept arguments that can be passed when it is + called. Any values from the dialog that need to be accessed from the wider + app should generally be stored in Session State. - Dismissing a dialog does not cause an app re-run. - You can close the dialog programmatically by executing `st.rerun()` explicitly inside of the decorated function. + A user can dismiss a modal dialog by clicking outside of it, clicking the + "**X**" in its upper-right corner, or pressing``ESC`` on their keyboard. + Dismissing a modal dialog does not trigger an app rerun. To close the modal + dialog programmatically, call ``st.rerun()`` explicitly inside of the + dialog function. - In order to pass state from dialog widgets to the app, you can leverage `st.session_state`. + ``st.experimental_dialog`` inherits behavior from |st.experimental_fragment|_. + When a user interacts with an input widget created inside a dialog function, + Streamlit only reruns the dialog function instead of the full script. + + Calling ``st.sidebar`` in a dialog function is not supported. + + Dialog code can interact with Session State, imported modules, and other + Streamlit elements created outside the dialog. Note that these interactions + are additive across multiple dialog reruns. You are responsible for + handling any side effects of that behavior. .. warning:: - Currently, a dialog may not open another dialog. - Also, only one dialog-decorated function may be called in a script run, which means that only one dialog can be open at any given time. + A dialog may not open another dialog. Only one dialog function may be + called in a script run, which means that only one dialog can be open at + any given time. + + .. |st.experimental_fragment| replace:: ``st.experimental_fragment`` + .. _st.experimental_fragment: https://docs.streamlit.io/develop/api-reference/execution-flow/st.fragment Parameters ---------- title : str - A string that will be used as the dialog's title. It cannot be empty. + The title to display at the top of the modal dialog. It cannot be empty. width : "small", "large" - The width of the dialog. Defaults to "small". - - Returns - ------- - A decorated function that, when called, inserts a dialog element context container. The container itself contains the decorated function's elements. + The width of the modal dialog. If ``width`` is ``"small`` (default), the + modal dialog will be 500 pixels wide. If ``width`` is ``"large"``, the + modal dialog will be about 750 pixels wide. Examples -------- - You can annotate a function to mark it as a Streamlit dialog function and pass arguments to it. You can either dismiss the dialog via the ESC-key or the X-button or close it programmatically and trigger a re-run by using `st.rerun()`. - Leverage `st.session_state` if you want to pass dialog widget states to the overall app: + The following example demonstrates the basic usage of ``@st.experimental_dialog``. + In this app, clicking "**A**" or "**B**" will open a modal dialog and prompt you + to enter a reason for your vote. In the modal dialog, click "**Submit**" to record + your vote into Session State and rerun the app. This will close the modal dialog + since the dialog function is not called during the full-script rerun. >>> import streamlit as st >>> - >>> @st.experimental_dialog("Streamlit Example Dialog") - >>> def example_dialog(some_arg: str, some_other_arg: int): - >>> st.write(f"You passed following args: {some_arg} | {some_other_arg}") - >>> # interacting with the text_input only re-runs `example_dialog` - >>> some_text_input = st.text_input("Type something:", key="example_dialog_some_text_input") - >>> # following write is updated when chaning the text_input inside the dialog - >>> st.write(f"You wrote '{some_text_input}' in the dialog") - >>> if st.button("Close the dialog"): + >>> @st.experimental_dialog("Cast your vote") + >>> def vote(item): + >>> st.write(f"Why is {item} your favorite?") + >>> reason = st.text_input("Because...") + >>> if st.button("Submit"): + >>> st.session_state.vote = {"item": item, "reason": reason} >>> st.rerun() >>> - >>> if st.button("Open dialog"): - >>> example_dialog("Some string arg", 42) - >>> - >>> # following write is updated with the dialog's text input when the dialog was opened, the text input was interacted with and a re-run was triggered, e.g. by clicking the Close-button defined in `example_dialog` - >>> st.write(f"You wrote '{st.session_state.get('example_dialog_some_text_input', '')}' in the dialog") + >>> if "vote" not in st.session_state: + >>> st.write("Vote for your favorite") + >>> if st.button("A"): + >>> vote("A") + >>> if st.button("B"): + >>> vote("B") + >>> else: + >>> f"You voted for {st.session_state.vote['item']} because {st.session_state.vote['reason']}" + + .. output:: + https://doc-dialog.streamlit.app/ + height: 350px """ diff --git a/lib/streamlit/elements/empty.py b/lib/streamlit/elements/empty.py index 840514ecd613..d246f5710460 100644 --- a/lib/streamlit/elements/empty.py +++ b/lib/streamlit/elements/empty.py @@ -33,12 +33,12 @@ def empty(self) -> DeltaGenerator: several elements at once (using a child multi-element container). To insert/replace/clear an element on the returned container, you can - use "with" notation or just call methods directly on the returned object. + use ``with`` notation or just call methods directly on the returned object. See examples below. Examples -------- - Overwriting elements in-place using "with" notation: + Overwriting elements in-place using ``with`` notation: >>> import streamlit as st >>> import time @@ -82,7 +82,7 @@ def _skeleton(self, *, height: int | None = None) -> DeltaGenerator: several elements at once (using a child multi-element container). To insert/replace/clear an element on the returned container, you can - use "with" notation or just call methods directly on the returned object. + use ``with`` notation or just call methods directly on the returned object. See some of the examples below. This is an internal method and should not be used directly. diff --git a/lib/streamlit/elements/form.py b/lib/streamlit/elements/form.py index 9d5b3b0c1686..449f5e162bce 100644 --- a/lib/streamlit/elements/form.py +++ b/lib/streamlit/elements/form.py @@ -123,7 +123,7 @@ def form( Submit button is pressed, all widget values inside the form will be sent to Streamlit in a batch. - To add elements to a form object, you can use "with" notation + To add elements to a form object, you can use ``with`` notation (preferred) or just call methods directly on the form. See examples below. @@ -157,7 +157,7 @@ def form( Examples -------- - Inserting elements using "with" notation: + Inserting elements using ``with`` notation: >>> import streamlit as st >>> diff --git a/lib/streamlit/elements/heading.py b/lib/streamlit/elements/heading.py index 373265594b31..bd9160ad1a15 100644 --- a/lib/streamlit/elements/heading.py +++ b/lib/streamlit/elements/heading.py @@ -69,8 +69,10 @@ def header( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. anchor : str or False The anchor name of the header that can be accessed with #anchor @@ -140,8 +142,10 @@ def subheader( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. anchor : str or False The anchor name of the header that can be accessed with #anchor @@ -213,8 +217,10 @@ def title( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. anchor : str or False The anchor name of the header that can be accessed with #anchor diff --git a/lib/streamlit/elements/layouts.py b/lib/streamlit/elements/layouts.py index 44826782e5f0..473e17fc4586 100644 --- a/lib/streamlit/elements/layouts.py +++ b/lib/streamlit/elements/layouts.py @@ -41,7 +41,7 @@ def container( multiple elements. This allows you to, for example, insert multiple elements into your app out of order. - To add elements to the returned container, you can use the "with" notation + To add elements to the returned container, you can use the ``with`` notation (preferred) or just call methods directly on the returned object. See examples below. @@ -67,7 +67,7 @@ def container( Examples -------- - Inserting elements using "with" notation: + Inserting elements using ``with`` notation: >>> import streamlit as st >>> @@ -151,7 +151,7 @@ def columns( Inserts a number of multi-element containers laid out side-by-side and returns a list of container objects. - To add elements to the returned containers, you can use the "with" notation + To add elements to the returned containers, you can use the ``with`` notation (preferred) or just call methods directly on the returned object. See examples below. @@ -183,7 +183,7 @@ def columns( Examples -------- - You can use the `with` notation to insert any element into a column: + You can use the ``with`` notation to insert any element into a column: >>> import streamlit as st >>> @@ -277,7 +277,7 @@ def tabs(self, tabs: Sequence[str]) -> Sequence[DeltaGenerator]: Tabs are a navigational element that allows users to easily move between groups of related content. - To add elements to the returned containers, you can use the "with" notation + To add elements to the returned containers, you can use the ``with`` notation (preferred) or just call methods directly on the returned object. See examples below. @@ -305,8 +305,10 @@ def tabs(self, tabs: Sequence[str]) -> Sequence[DeltaGenerator]: * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -319,7 +321,7 @@ def tabs(self, tabs: Sequence[str]) -> Sequence[DeltaGenerator]: Examples -------- - You can use the `with` notation to insert any element into a tab: + You can use the ``with`` notation to insert any element into a tab: >>> import streamlit as st >>> @@ -390,7 +392,7 @@ def expander(self, label: str, expanded: bool = False) -> DeltaGenerator: and can be expanded or collapsed by the user. When collapsed, all that is visible is the provided label. - To add elements to the returned container, you can use the "with" notation + To add elements to the returned container, you can use the ``with`` notation (preferred) or just call methods directly on the returned object. See examples below. @@ -416,8 +418,10 @@ def expander(self, label: str, expanded: bool = False) -> DeltaGenerator: * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -428,18 +432,18 @@ def expander(self, label: str, expanded: bool = False) -> DeltaGenerator: Examples -------- - You can use the `with` notation to insert any element into an expander + You can use the ``with`` notation to insert any element into an expander >>> import streamlit as st >>> >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]}) >>> >>> with st.expander("See explanation"): - ... st.write(\"\"\" + ... st.write(''' ... The chart above shows some numbers I picked for you. ... I rolled actual dice for these, so they're *guaranteed* to ... be random. - ... \"\"\") + ... ''') ... st.image("https://static.streamlit.io/examples/dice.jpg") .. output :: @@ -453,11 +457,11 @@ def expander(self, label: str, expanded: bool = False) -> DeltaGenerator: >>> st.bar_chart({"data": [1, 5, 2, 6, 2, 1]}) >>> >>> expander = st.expander("See explanation") - >>> expander.write(\"\"\" + >>> expander.write(''' ... The chart above shows some numbers I picked for you. ... I rolled actual dice for these, so they're *guaranteed* to ... be random. - ... \"\"\") + ... ''') >>> expander.image("https://static.streamlit.io/examples/dice.jpg") .. output :: @@ -523,8 +527,10 @@ def popover( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -545,7 +551,7 @@ def popover( Examples -------- - You can use the `with` notation to insert any element into a popover: + You can use the ``with`` notation to insert any element into a popover: >>> import streamlit as st >>> @@ -609,11 +615,11 @@ def status( The label, state, and expanded state can all be updated by calling ``.update()`` on the returned object. To add elements to the returned container, you can - use "with" notation (preferred) or just call methods directly on the returned + use ``with`` notation (preferred) or just call methods directly on the returned object. By default, ``st.status()`` initializes in the "running" state. When called using - "with" notation, it automatically updates to the "complete" state at the end + ``with`` notation, it automatically updates to the "complete" state at the end of the "with" block. See examples below for more details. Parameters @@ -636,8 +642,10 @@ def status( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -667,7 +675,7 @@ def status( Examples -------- - You can use the `with` notation to insert any element into an status container: + You can use the ``with`` notation to insert any element into an status container: >>> import time >>> import streamlit as st @@ -680,13 +688,13 @@ def status( ... st.write("Downloading data...") ... time.sleep(1) >>> - >>> st.button('Rerun') + >>> st.button("Rerun") .. output :: https://doc-status.streamlit.app/ height: 300px - You can also use `.update()` on the container to change the label, state, + You can also use ``.update()`` on the container to change the label, state, or expanded state: >>> import time @@ -701,7 +709,7 @@ def status( ... time.sleep(1) ... status.update(label="Download complete!", state="complete", expanded=False) >>> - >>> st.button('Rerun') + >>> st.button("Rerun") .. output :: https://doc-status-update.streamlit.app/ diff --git a/lib/streamlit/elements/lib/column_types.py b/lib/streamlit/elements/lib/column_types.py index d43a46367dba..a2af496346c2 100644 --- a/lib/streamlit/elements/lib/column_types.py +++ b/lib/streamlit/elements/lib/column_types.py @@ -533,7 +533,9 @@ def LinkColumn( * A regular expression (JS flavor, detected by usage of parentheses) to extract a part of the URL via a capture group, e.g. ``"https://(.*?)\\.example\\.com"`` - to extract the display text "foo" from the URL "https://foo.example.com". + to extract the display text "foo" from the URL "\\https://foo.example.com". + + .. Comment: The backslash in front of foo.example.com prevents a hyperlink. For more complex cases, you may use `Pandas Styler's format \ `_ diff --git a/lib/streamlit/elements/markdown.py b/lib/streamlit/elements/markdown.py index cc153d04f16c..489c0b8e694e 100644 --- a/lib/streamlit/elements/markdown.py +++ b/lib/streamlit/elements/markdown.py @@ -58,8 +58,10 @@ def markdown( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. unsafe_allow_html : bool By default, any HTML tags found in the body will be escaped and @@ -82,7 +84,7 @@ def markdown( >>> st.markdown("*Streamlit* is **really** ***cool***.") >>> st.markdown(''' ... :red[Streamlit] :orange[can] :green[write] :blue[text] :violet[in] - ... :gray[pretty] :rainbow[colors].''') + ... :gray[pretty] :rainbow[colors] and :blue-background[highlight] text.''') >>> st.markdown("Here's a bouquet —\ ... :tulip::cherry_blossom::rose::hibiscus::sunflower::blossom:") >>> @@ -95,7 +97,7 @@ def markdown( .. output:: https://doc-markdown.streamlit.app/ - height: 260px + height: 350px """ markdown_proto = MarkdownProto() @@ -177,8 +179,10 @@ def caption( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. unsafe_allow_html : bool By default, any HTML tags found in strings will be escaped and diff --git a/lib/streamlit/elements/media.py b/lib/streamlit/elements/media.py index 69d5c283b7dd..bac054ec290a 100644 --- a/lib/streamlit/elements/media.py +++ b/lib/streamlit/elements/media.py @@ -122,10 +122,9 @@ def audio( loop: bool Whether the audio should loop playback. autoplay: bool - Whether the audio should start playing automatically. - Browsers will not autoplay audio files if the user has not interacted with - the page yet, for example by clicking on the page while it loads. - Defaults to False. + Whether the audio file should start playing automatically. This is + ``False`` by default. Browsers will not autoplay audio files if the + user has not interacted with the page by clicking somewhere. Examples -------- @@ -227,7 +226,7 @@ def video( one of the following: * ``None`` (default): The element plays from the beginning. - * An``int`` or ``float`` specifying the time in seconds. ``float`` + * An ``int`` or ``float`` specifying the time in seconds. ``float`` values are rounded down to whole seconds. * A string specifying the time in a format supported by `Pandas' Timedelta constructor `_, @@ -275,14 +274,15 @@ def video( loop: bool Whether the video should loop playback. autoplay: bool - Whether the video should start playing automatically. - Browsers will not autoplay video files if the user has not interacted with - the page yet, for example by clicking on the page while it loads. - To enable autoplay without user interaction, you can set muted=True. - Defaults to False. + Whether the video should start playing automatically. This is + ``False`` by default. Browsers will not autoplay unmuted videos + if the user has not interacted with the page by clicking somewhere. + To enable autoplay without user interaction, you must also set + ``muted=True``. muted: bool - Whether the video should play with the audio silenced. This can be used to - enable autoplay without user interaction. Defaults to False. + Whether the video should play with the audio silenced. This is + ``False`` by default. Use this in conjunction with ``autoplay=True`` + to enable autoplay without user interaction. Example ------- diff --git a/lib/streamlit/elements/metric.py b/lib/streamlit/elements/metric.py index a954ec72ef73..3c9d45634c00 100644 --- a/lib/streamlit/elements/metric.py +++ b/lib/streamlit/elements/metric.py @@ -81,8 +81,10 @@ def metric( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by diff --git a/lib/streamlit/elements/progress.py b/lib/streamlit/elements/progress.py index 19c50cbec712..8ed177a652e1 100644 --- a/lib/streamlit/elements/progress.py +++ b/lib/streamlit/elements/progress.py @@ -119,8 +119,10 @@ def progress(self, value: FloatOrInt, text: str | None = None) -> DeltaGenerator * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by diff --git a/lib/streamlit/elements/toast.py b/lib/streamlit/elements/toast.py index 6e2b8b932e26..b9f0cf81821e 100644 --- a/lib/streamlit/elements/toast.py +++ b/lib/streamlit/elements/toast.py @@ -69,13 +69,27 @@ def toast( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. - icon : str or None - An optional argument that specifies an emoji to use as - the icon for the toast. Shortcodes are not allowed, please use a - single character instead. E.g. "🚨", "🔥", "🤖", etc. - Defaults to None, which means no icon is displayed. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. + + icon : str, None + An optional emoji or icon to display next to the alert. If ``icon`` + is ``None`` (default), no icon is displayed. If ``icon`` is a + string, the following options are valid: + + * A single-character emoji. For example, you can set ``icon="🚨"`` + or ``icon="🔥"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Example ------- diff --git a/lib/streamlit/elements/widgets/button.py b/lib/streamlit/elements/widgets/button.py index e97ece7904c2..7c196fdf6de8 100644 --- a/lib/streamlit/elements/widgets/button.py +++ b/lib/streamlit/elements/widgets/button.py @@ -99,8 +99,10 @@ def button( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -140,10 +142,10 @@ def button( >>> import streamlit as st >>> >>> st.button("Reset", type="primary") - >>> if st.button('Say hello'): - ... st.write('Why hello there') + >>> if st.button("Say hello"): + ... st.write("Why hello there") ... else: - ... st.write('Goodbye') + ... st.write("Goodbye") .. output:: https://doc-buton.streamlit.app/ @@ -219,8 +221,10 @@ def download_button( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -278,15 +282,15 @@ def download_button( >>> @st.cache_data ... def convert_df(df): ... # IMPORTANT: Cache the conversion to prevent computation on every rerun - ... return df.to_csv().encode('utf-8') + ... return df.to_csv().encode("utf-8") >>> >>> csv = convert_df(my_large_df) >>> >>> st.download_button( ... label="Download data as CSV", ... data=csv, - ... file_name='large_df.csv', - ... mime='text/csv', + ... file_name="large_df.csv", + ... mime="text/csv", ... ) Download a string as a file: @@ -294,15 +298,15 @@ def download_button( >>> import streamlit as st >>> >>> text_contents = '''This is some text''' - >>> st.download_button('Download some text', text_contents) + >>> st.download_button("Download some text", text_contents) Download a binary file: >>> import streamlit as st >>> - >>> binary_contents = b'example content' - >>> # Defaults to 'application/octet-stream' - >>> st.download_button('Download binary file', binary_contents) + >>> binary_contents = b"example content" + >>> # Defaults to "application/octet-stream" + >>> st.download_button("Download binary file", binary_contents) Download an image: @@ -380,8 +384,10 @@ def link_button( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -473,8 +479,10 @@ def page_link( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by diff --git a/lib/streamlit/elements/widgets/camera_input.py b/lib/streamlit/elements/widgets/camera_input.py index e9c9a6dfae48..ad7dd487fb20 100644 --- a/lib/streamlit/elements/widgets/camera_input.py +++ b/lib/streamlit/elements/widgets/camera_input.py @@ -114,8 +114,10 @@ def camera_input( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by diff --git a/lib/streamlit/elements/widgets/chat.py b/lib/streamlit/elements/widgets/chat.py index 031822fd1820..8f33b07507f1 100644 --- a/lib/streamlit/elements/widgets/chat.py +++ b/lib/streamlit/elements/widgets/chat.py @@ -140,18 +140,35 @@ def chat_message( accessibility label. For accessibility reasons, you should not use an empty string. - avatar : str, numpy.ndarray, or BytesIO - The avatar shown next to the message. Can be one of: + avatar : Anything supported by st.image, str, or None + The avatar shown next to the message. - * A single emoji, e.g. "🧑‍💻", "🤖", "🦖". Shortcodes are not supported. + If ``avatar`` is ``None`` (default), the icon will be determined + from ``name`` as follows: - * An image using one of the formats allowed for ``st.image``: path of a local - image file; URL to fetch the image from; an SVG image; array of shape - (w,h) or (w,h,1) for a monochrome image, (w,h,3) for a color image, - or (w,h,4) for an RGBA image. + * If ``name`` is ``"user"`` or ``"human"``, the message will have a + default user icon. - If None (default), uses default icons if ``name`` is "user", - "assistant", "ai", "human" or the first letter of the ``name`` value. + * If ``name`` is ``"ai"`` or ``"assistant"``, the message will have + a default bot icon. + + * For all other values of ``name``, the message will show the first + letter of the name. + + In addition to the types supported by ``st.image`` (like URLs or numpy + arrays), the following strings are valid: + + * A single-character emoji. For example, you can set ``avatar="🧑‍💻"`` + or ``avatar="🦖"``. Emoji short codes are not supported. + + * An icon from the Material Symbols library (outlined style) in the + format ``":material/icon_name:"`` where "icon_name" is the name + of the icon in snake case. + + For example, ``icon=":material/thumb_up:"`` will display the + Thumb Up icon. Find additional icons in the `Material Symbols \ + `_ + font library. Returns ------- diff --git a/lib/streamlit/elements/widgets/checkbox.py b/lib/streamlit/elements/widgets/checkbox.py index 058138dcd689..c8df28b11176 100644 --- a/lib/streamlit/elements/widgets/checkbox.py +++ b/lib/streamlit/elements/widgets/checkbox.py @@ -88,8 +88,10 @@ def checkbox( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -132,10 +134,10 @@ def checkbox( ------- >>> import streamlit as st >>> - >>> agree = st.checkbox('I agree') + >>> agree = st.checkbox("I agree") >>> >>> if agree: - ... st.write('Great!') + ... st.write("Great!") .. output:: https://doc-checkbox.streamlit.app/ @@ -192,8 +194,10 @@ def toggle( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -236,10 +240,10 @@ def toggle( ------- >>> import streamlit as st >>> - >>> on = st.toggle('Activate feature') + >>> on = st.toggle("Activate feature") >>> >>> if on: - ... st.write('Feature activated!') + ... st.write("Feature activated!") .. output:: https://doc-toggle.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/color_picker.py b/lib/streamlit/elements/widgets/color_picker.py index 07a70b439a5a..13497434d450 100644 --- a/lib/streamlit/elements/widgets/color_picker.py +++ b/lib/streamlit/elements/widgets/color_picker.py @@ -88,8 +88,10 @@ def color_picker( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -134,8 +136,8 @@ def color_picker( ------- >>> import streamlit as st >>> - >>> color = st.color_picker('Pick A Color', '#00f900') - >>> st.write('The current color is', color) + >>> color = st.color_picker("Pick A Color", "#00f900") + >>> st.write("The current color is", color) .. output:: https://doc-color-picker.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/file_uploader.py b/lib/streamlit/elements/widgets/file_uploader.py index a2a3ba60e996..488a82eeed17 100644 --- a/lib/streamlit/elements/widgets/file_uploader.py +++ b/lib/streamlit/elements/widgets/file_uploader.py @@ -243,7 +243,7 @@ def file_uploader( ) -> UploadedFile | list[UploadedFile] | None: r"""Display a file uploader widget. By default, uploaded files are limited to 200MB. You can configure - this using the `server.maxUploadSize` config option. For more info + this using the ``server.maxUploadSize`` config option. For more info on how to set config options, see https://docs.streamlit.io/library/advanced-features/configuration#set-configuration-options @@ -266,8 +266,10 @@ def file_uploader( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by diff --git a/lib/streamlit/elements/widgets/multiselect.py b/lib/streamlit/elements/widgets/multiselect.py index 3b558fa67edb..27dcaaf00782 100644 --- a/lib/streamlit/elements/widgets/multiselect.py +++ b/lib/streamlit/elements/widgets/multiselect.py @@ -181,8 +181,10 @@ def multiselect( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -240,11 +242,11 @@ def multiselect( >>> import streamlit as st >>> >>> options = st.multiselect( - ... 'What are your favorite colors', - ... ['Green', 'Yellow', 'Red', 'Blue'], - ... ['Yellow', 'Red']) + ... "What are your favorite colors", + ... ["Green", "Yellow", "Red", "Blue"], + ... ["Yellow", "Red"]) >>> - >>> st.write('You selected:', options) + >>> st.write("You selected:", options) .. output:: https://doc-multiselect.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/number_input.py b/lib/streamlit/elements/widgets/number_input.py index 7f6d972ac85a..ff2059dfa8f7 100644 --- a/lib/streamlit/elements/widgets/number_input.py +++ b/lib/streamlit/elements/widgets/number_input.py @@ -158,8 +158,10 @@ def number_input( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -222,8 +224,8 @@ def number_input( ------- >>> import streamlit as st >>> - >>> number = st.number_input('Insert a number') - >>> st.write('The current number is ', number) + >>> number = st.number_input("Insert a number") + >>> st.write("The current number is ", number) .. output:: https://doc-number-input.streamlit.app/ @@ -234,7 +236,7 @@ def number_input( >>> import streamlit as st >>> >>> number = st.number_input("Insert a number", value=None, placeholder="Type a number...") - >>> st.write('The current number is ', number) + >>> st.write("The current number is ", number) .. output:: https://doc-number-input-empty.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/radio.py b/lib/streamlit/elements/widgets/radio.py index d89b0f71ecae..1b553adc6b5d 100644 --- a/lib/streamlit/elements/widgets/radio.py +++ b/lib/streamlit/elements/widgets/radio.py @@ -121,8 +121,10 @@ def radio( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -189,10 +191,10 @@ def radio( ... [":rainbow[Comedy]", "***Drama***", "Documentary :movie_camera:"], ... captions = ["Laugh out loud.", "Get the popcorn.", "Never stop learning."]) >>> - >>> if genre == ':rainbow[Comedy]': - ... st.write('You selected comedy.') + >>> if genre == ":rainbow[Comedy]": + ... st.write("You selected comedy.") ... else: - ... st.write("You didn\'t select comedy.") + ... st.write("You didn't select comedy.") .. output:: https://doc-radio.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/select_slider.py b/lib/streamlit/elements/widgets/select_slider.py index 201c379ad8c1..81da21eb678c 100644 --- a/lib/streamlit/elements/widgets/select_slider.py +++ b/lib/streamlit/elements/widgets/select_slider.py @@ -149,8 +149,10 @@ def select_slider( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -207,19 +209,19 @@ def select_slider( >>> import streamlit as st >>> >>> color = st.select_slider( - ... 'Select a color of the rainbow', - ... options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']) - >>> st.write('My favorite color is', color) + ... "Select a color of the rainbow", + ... options=["red", "orange", "yellow", "green", "blue", "indigo", "violet"]) + >>> st.write("My favorite color is", color) And here's an example of a range select slider: >>> import streamlit as st >>> >>> start_color, end_color = st.select_slider( - ... 'Select a range of color wavelength', - ... options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'], - ... value=('red', 'blue')) - >>> st.write('You selected wavelengths between', start_color, 'and', end_color) + ... "Select a range of color wavelength", + ... options=["red", "orange", "yellow", "green", "blue", "indigo", "violet"], + ... value=("red", "blue")) + >>> st.write("You selected wavelengths between", start_color, "and", end_color) .. output:: https://doc-select-slider.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/selectbox.py b/lib/streamlit/elements/widgets/selectbox.py index fb1f1684afe2..131707927136 100644 --- a/lib/streamlit/elements/widgets/selectbox.py +++ b/lib/streamlit/elements/widgets/selectbox.py @@ -113,8 +113,10 @@ def selectbox( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -150,7 +152,7 @@ def selectbox( An optional dict of kwargs to pass to the callback. placeholder : str A string to display when no options are selected. - Defaults to 'Choose an option'. + Defaults to "Choose an option". disabled : bool An optional boolean, which disables the selectbox if set to True. The default is False. @@ -170,10 +172,10 @@ def selectbox( >>> import streamlit as st >>> >>> option = st.selectbox( - ... 'How would you like to be contacted?', - ... ('Email', 'Home phone', 'Mobile phone')) + ... "How would you like to be contacted?", + ... ("Email", "Home phone", "Mobile phone")) >>> - >>> st.write('You selected:', option) + >>> st.write("You selected:", option) .. output:: https://doc-selectbox.streamlit.app/ @@ -190,7 +192,7 @@ def selectbox( ... placeholder="Select contact method...", ... ) >>> - >>> st.write('You selected:', option) + >>> st.write("You selected:", option) .. output:: https://doc-selectbox-empty.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/slider.py b/lib/streamlit/elements/widgets/slider.py index f8640078c6b1..61b7dbf7809f 100644 --- a/lib/streamlit/elements/widgets/slider.py +++ b/lib/streamlit/elements/widgets/slider.py @@ -191,11 +191,11 @@ def slider( This supports int, float, date, time, and datetime types. This also allows you to render a range slider by passing a two-element - tuple or list as the `value`. + tuple or list as the ``value``. - The difference between `st.slider` and `st.select_slider` is that - `slider` only accepts numerical or date/time data and takes a range as - input, while `select_slider` accepts any datatype and takes an iterable + The difference between ``st.slider`` and ``st.select_slider`` is that + ``slider`` only accepts numerical or date/time data and takes a range as + input, while ``select_slider`` accepts any datatype and takes an iterable set of options. .. note:: @@ -223,8 +223,10 @@ def slider( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -291,17 +293,17 @@ def slider( -------- >>> import streamlit as st >>> - >>> age = st.slider('How old are you?', 0, 130, 25) - >>> st.write("I'm ", age, 'years old') + >>> age = st.slider("How old are you?", 0, 130, 25) + >>> st.write("I'm ", age, "years old") And here's an example of a range slider: >>> import streamlit as st >>> >>> values = st.slider( - ... 'Select a range of values', + ... "Select a range of values", ... 0.0, 100.0, (25.0, 75.0)) - >>> st.write('Values:', values) + >>> st.write("Values:", values) This is a range time slider: diff --git a/lib/streamlit/elements/widgets/text_widgets.py b/lib/streamlit/elements/widgets/text_widgets.py index 0efdf934cdf7..6315b8529aa3 100644 --- a/lib/streamlit/elements/widgets/text_widgets.py +++ b/lib/streamlit/elements/widgets/text_widgets.py @@ -152,8 +152,10 @@ def text_input( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -212,8 +214,8 @@ def text_input( ------- >>> import streamlit as st >>> - >>> title = st.text_input('Movie title', 'Life of Brian') - >>> st.write('The current movie title is', title) + >>> title = st.text_input("Movie title", "Life of Brian") + >>> st.write("The current movie title is", title) .. output:: https://doc-text-input.streamlit.app/ @@ -418,8 +420,10 @@ def text_area( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -481,7 +485,7 @@ def text_area( ... "despair, (...)", ... ) >>> - >>> st.write(f'You wrote {len(txt)} characters.') + >>> st.write(f"You wrote {len(txt)} characters.") .. output:: https://doc-text-area.streamlit.app/ diff --git a/lib/streamlit/elements/widgets/time_widgets.py b/lib/streamlit/elements/widgets/time_widgets.py index e4056ff0e284..1d3e4ab1939f 100644 --- a/lib/streamlit/elements/widgets/time_widgets.py +++ b/lib/streamlit/elements/widgets/time_widgets.py @@ -323,8 +323,10 @@ def time_input( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -374,8 +376,8 @@ def time_input( >>> import datetime >>> import streamlit as st >>> - >>> t = st.time_input('Set an alarm for', datetime.time(8, 45)) - >>> st.write('Alarm is set for', t) + >>> t = st.time_input("Set an alarm for", datetime.time(8, 45)) + >>> st.write("Alarm is set for", t) .. output:: https://doc-time-input.streamlit.app/ @@ -386,8 +388,8 @@ def time_input( >>> import datetime >>> import streamlit as st >>> - >>> t = st.time_input('Set an alarm for', value=None) - >>> st.write('Alarm is set for', t) + >>> t = st.time_input("Set an alarm for", value=None) + >>> st.write("Alarm is set for", t) .. output:: https://doc-time-input-empty.streamlit.app/ @@ -548,8 +550,10 @@ def date_input( * Colored text and background colors for text, using the syntax ``:color[text to be colored]`` and ``:color-background[text to be colored]``, - respectively — where ``color`` needs to be replaced with any of the following + respectively. ``color`` must be replaced with any of the following supported colors: blue, green, orange, red, violet, gray/grey, rainbow. + For example, you can use ``:orange[your text here]`` or + ``:blue-background[your text here]``. Unsupported elements are unwrapped so only their children (text contents) render. Display unsupported elements as literal characters by @@ -585,7 +589,7 @@ def date_input( An optional dict of kwargs to pass to the callback. format : str A format string controlling how the interface should display dates. - Supports “YYYY/MM/DD” (default), “DD/MM/YYYY”, or “MM/DD/YYYY”. + Supports "YYYY/MM/DD" (default), "DD/MM/YYYY", or "MM/DD/YYYY". You may also use a period (.) or hyphen (-) as separators. disabled : bool An optional boolean, which disables the date input if set to True. @@ -609,7 +613,7 @@ def date_input( >>> import streamlit as st >>> >>> d = st.date_input("When's your birthday", datetime.date(2019, 7, 6)) - >>> st.write('Your birthday is:', d) + >>> st.write("Your birthday is:", d) .. output:: https://doc-date-input.streamlit.app/ @@ -642,7 +646,7 @@ def date_input( >>> import streamlit as st >>> >>> d = st.date_input("When's your birthday", value=None) - >>> st.write('Your birthday is:', d) + >>> st.write("Your birthday is:", d) .. output:: https://doc-date-input-empty.streamlit.app/ diff --git a/lib/streamlit/runtime/caching/cache_utils.py b/lib/streamlit/runtime/caching/cache_utils.py index 621738ae1e9e..ab6f7c47f93f 100644 --- a/lib/streamlit/runtime/caching/cache_utils.py +++ b/lib/streamlit/runtime/caching/cache_utils.py @@ -304,9 +304,40 @@ def _handle_cache_miss( ) def clear(self, *args, **kwargs): - """Clear the wrapped function's associated cache. - If no arguments are passed, clear the cache of all values. - If args/kwargs are provided, clear the cached value for these arguments only.""" + """Clear the cached function's associated cache. + + If no arguments are passed, Streamlit will clear all values cached for + the function. If arguments are passed, Streamlit will clear the cached + value for these arguments only. + + Parameters + ---------- + *args: Any + Arguments of the cached functions. + **kwargs: Any + Keyword arguments of the cached function. + + Example + ------- + >>> import streamlit as st + >>> import time + >>> + >>> @st.cache_data + >>> def foo(bar): + >>> time.sleep(2) + >>> st.write(f"Executed foo({bar}).") + >>> return bar + >>> + >>> if st.button("Clear all cached values for `foo`", on_click=foo.clear): + >>> foo.clear() + >>> + >>> if st.button("Clear the cached value of `foo(1)`"): + >>> foo.clear(1) + >>> + >>> foo(1) + >>> foo(2) + + """ cache = self._info.get_function_cache(self._function_key) if args or kwargs: key = _make_value_key( diff --git a/lib/streamlit/runtime/state/query_params_proxy.py b/lib/streamlit/runtime/state/query_params_proxy.py index 430ccca452f9..c5d2deddd632 100644 --- a/lib/streamlit/runtime/state/query_params_proxy.py +++ b/lib/streamlit/runtime/state/query_params_proxy.py @@ -171,26 +171,36 @@ def from_dict(self, mapping: SupportsKeysAndGetItem[str, str]) -> None: ... @gather_metrics("query_params.from_dict") - def from_dict(self, other): + def from_dict(self, params): """ Set all of the query parameters from a dictionary or dictionary-like object. - This method primarily exists for advanced users who want to be able to control - multiple query string parameters in a single update. To set individual - query string parameters you should still use `st.query_params["parameter"] = "value"` - or `st.query_params.parameter = "value"`. + This method primarily exists for advanced users who want to control + multiple query parameters in a single update. To set individual query + parameters, use key or attribute notation instead. - `embed` and `embed_options` may not be set via this method and may not be keys in the - `other` dictionary. + This method inherits limitations from ``st.query_params`` and can't be + used to set embedding options as described in `Embed your app \ + `_. - Note that this method is NOT a direct inverse of `st.query_params.to_dict()` when - the URL query string contains multiple values for a single key. A true inverse - operation for from_dict is `{key: st.query_params.get_all(key) for key st.query_params}`. + To handle repeated keys, the value in a key-value pair should be a list. + + .. note:: + ``.from_dict()`` is not a direct inverse of ``.to_dict()`` if + you are working with repeated keys. A true inverse operation is + ``{key: st.query_params.get_all(key) for key st.query_params}``. Parameters + ---------- + params: dict + A dictionary used to replace the current query parameters. + + Example ------- - other: SupportsKeysAndGetItem[str, str] | Iterable[tuple[str, str]] - A dictionary used to replace the current query_params. + >>> import streamlit as st + >>> + >>> st.query_params.from_dict({"foo": "bar", "baz": [1, "two"]}) + """ with get_session_state().query_params() as qp: - return qp.from_dict(other) + return qp.from_dict(params)