- Contents
- st.popover
- PopoverContainer
st.popover
Insert a popover container.
Inserts a multi-element container as a popover. It consists of a button-like element and a container that opens when the button is clicked.
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.
Interacting with widgets inside of an open popover will rerun the app while keeping the popover open. Clicking outside of the popover will close it.
By default, all content within the popover is computed and sent to the frontend, and the app doesn't rerun when the popover is opened or closed. To enable lazy execution where content only runs when the popover is open, use on_change="rerun" or pass a callable to on_change. The .open property indicates whether the popover is currently open, letting you conditionally render expensive content.
Note
To follow best design practices, don't nest popovers.
| Function signature[source] | |
|---|---|
st.popover(label, *, type="secondary", help=None, icon=None, disabled=False, use_container_width=None, width="content", key=None, on_change="ignore", args=None, kwargs=None) | |
| Parameters | |
label (str) | The label of the button that opens the popover container. The label can optionally contain GitHub-flavored Markdown of the following types: Bold, Italics, Strikethroughs, Inline Code, Links, and Images. Images display like icons, with a max height equal to the font height. Unsupported Markdown elements are unwrapped so only their children (text contents) render. Common block-level Markdown (headings, lists, blockquotes) is automatically escaped and displays as literal text in labels. See the body parameter of st.markdown for additional, supported Markdown directives. |
help (str or None) | A tooltip that gets displayed when the popover button is hovered over. If this is None (default), no tooltip is displayed. The tooltip can optionally contain GitHub-flavored Markdown, including the Markdown directives described in the body parameter of st.markdown. |
type ("primary", "secondary", or "tertiary") | An optional string that specifies the button type. This can be one of the following:
|
icon (str) | An optional emoji or icon to display next to the button label. If icon is None (default), no icon is displayed. If icon is a string, the following options are valid:
|
disabled (bool) | An optional boolean that disables the popover button if set to True. The default is False. |
use_container_width (bool) |
delete
use_container_width is deprecated and will be removed in a future release. For use_container_width=True, use width="stretch". For use_container_width=False, use width="content". Whether to expand the button's width to fill its parent container. If use_container_width is False (default), Streamlit sizes the button to fit its content. If use_container_width is True, the width of the button matches its parent container. In both cases, if the content of the button is wider than the parent container, the content will line wrap. The popover container's minimum width matches the width of its button. The popover container may be wider than its button to fit the container's content. |
width (int, "stretch", or "content") | The width of the button. This can be one of the following:
The popover container's minimum width matches the width of its button. The popover container may be wider than its button to fit the container's contents. |
key (str, int, or None) | An optional string or integer to use as the unique key for the widget. If this is None (default), a key will be generated for the widget based on the values of the other parameters. No two widgets may have the same key. When on_change is set to "rerun" or a callable, setting a key lets you read or update the open/closed state via st.session_state[key]. For more details, see Widget behavior. |
on_change ("ignore", "rerun", or callable) | How the popover should respond when the user opens or closes it. This controls whether the popover tracks state and triggers reruns. on_change can be one of the following values:
When the popover tracks state, it can't be used inside Streamlit cache-decorated functions. |
args (list or tuple or None) | An optional list or tuple of args to pass to the on_change callback. |
kwargs (dict or None) | An optional dict of kwargs to pass to the on_change callback. |
| Returns | |
(PopoverContainer) | A PopoverContainer object with an .open property to return the current state of the popover if the popover tracks state. |
Examples
Example 1: Use context management You can use the with notation to insert any element into a popover:
Example 2: Call methods directly
You can call methods directly on the returned object:
Example 3: Programmatically control the popover state
You can use a key to programmatically control the popover state or access the state in callbacks. You must set the on_change parameter for the popover to track state.
PopoverContainer
A container returned by st.popover.
PopoverContainer is a Streamlit container with an .open property for lazy execution. Use with notation or call methods directly on the container to add elements to the popover.
| Attributes | |
open (bool or None) | Whether the popover is open. This is True if the popover is open and False if it's closed, or None if state tracking isn't enabled. |
Examples
Example 1: Lazy loading content
Example 2: Conditionally render content outside of the popover
Still have questions?
Our forums are full of helpful information and Streamlit experts.
