Coming soon: st.dialog

Hey all! :wave:

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!

You can find the demo app with instructions here: https://dialog-preview.streamlit.app/

Basic example

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!

Happy Streamlit-ing! :balloon:

13 Likes

This will for sure be a great addition. I’ll be using it as soon as it’s put out