Can't use buttons within @st.experimental_dialog?

I have several buttons within a dialog. Even when they don’t do anything, clicking them gives the following error.

The button within the dialog is defined as st.button("Select",key=1)

When clicked, everything disappears from the dialog (except the label), and I get the error RuntimeError: Could not find fragment with id 1c78f2182f4bcfbd2cda9b9971306dc7

This is true for all of the buttons in the dialog, even though I haven’t yet written the code that defines what should happen once their pressed. My assumption is that clicking the button causes the whole page to rerun and streamlit is losing track of the items in the dialog.

Am I doing something wrong or is this a bug?

How could we possibly know?

@Goyo Code to reproduce:

import streamlit as st

st.title("Text outside of dialog box")

@st.experimental_dialog("Test Dialog")
def dialog_box():
    st.write("Text in dialog box")
    st.button("Press me to see error")

st.button("Show dialog box", on_click=dialog_box)

This is running locally using streamlit 1.35.0

After a look at the documentation I would say this is a bug. However, I am not sure that opening dialogs from callbacks is intended to be supported.

FWIW I often see unexpected behavior when I create streamlit widgets from callbacks, so I just don’t do it anymore. Instead I use callbacks to change state, then create widgets outside the callbacks, based on the state.

I have the same issue event with text_input


email = st.text_input("Email", key="email_input")
password = st.text_input("Password", type="password")

Whenever I typed in email in the dialog, I will see the same fragment not found error

Traceback (most recent call last):
File “/Users/jocelinho/Documents/Jocelin/Projects/lawsome/venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 595, in _run_script
raise RuntimeError(
RuntimeError: Could not find fragment with id 1c78f2182f4bcfbd2cda9b9971306dc7

A staff member just confirmed that this is not supported (yet).

As part of de-experimentalizing fragments and dialogs in version 1.37.0, fragments can now be nested and used in callbacks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.