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()