We’re excited to share a prototype for st.dialog. This new feature will let you show a modal dialog on top of your app. It’s one of our most requested features ever (~400 upvotes on GitHub), so we’re very excited to ship this soon!
To create a dialog, you need to define a function with the dialog content and decorate
it with @st.experimental_dialog. This works the same way as the new fragments feature we launched in 1.33. To open the dialog, just call the function.
# Create a dialog function. Every element in it will show inside the dialog.
@st.experimental_dialog("Dialog title")
def show_dialog():
st.write("This text is inside the dialog.")
st.text_input("It can also contain widgets and any other elements.")
if st.button("Close"):
st.rerun()
# Open the dialog when the button is clicked.
if st.button("Open dialog"):
show_dialog()
Timeline
We’re expecting to merge this in the next few days and release with the 1.34 release in early May.
Feedback
Please let us know what you think, no matter if positive or negative. You can comment below or on the GitHub issue. Also, let us know if you find any bugs!
Such a great feature! I‘m currently using it.
But here’s one confusion: Can I have any method to dismiss the dialog ( just as the “X” button) instead of using “st.rerun()”. Since that I want to use a custom button to close it without rerunning the script.
Hey @T11, that’s currently not possible but you’re more than welcome to open a feature request on GitHub! There’s also a slightly related issue here (basically the opposite of what you want ) but I think it’s worth to track your idea as a separate issue.
Thank you so much for you reply! I’m now using a overlay to meet my requirement (avoid reclicking while the script is running). I’ll open a request later if possible. Thanks again for your great work!
@st.dialog("Sample Prompts / Questions")
def show_dialog():
markdown_content = generate_questions_markdown()
st.markdown(markdown_content)
# Open the dialog when the button is clicked.
if st.button("Prompting Help"):
show_dialog()
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.