streamlit / streamlit

Streamlit — A faster way to build and share data apps.
https://streamlit.io
Apache License 2.0
34.43k stars 2.98k forks source link

experimental_dialog after st.rerun, opens wrongly the app inside the dialog #9107

Closed TheDjaangoo closed 2 weeks ago

TheDjaangoo commented 1 month ago

Checklist

Summary

When I run the code on the vm, user submits the button then we start ML model that takes (1-2) seconds and rerun is done.

Then code is refreshing the site, but the site is opening again inside the modal, not outside (with modal, closed) as it should. (The same view in the end should be like at the first print screen)

One thing to note. The error does not happen every time. Also it is more common on very weak machine, with not so much memmory and cpu. See step by step the images

First open modal

Screenshot 2024-07-19 at 12 37 52

Second add changes and submit

Screenshot 2024-07-19 at 12 38 56

Here we can see, that app opens after the refresh inside the modal, not "normally"

image

Reproducible Code Example

@st.experimental_dialog("test", width="large")
def edit_generated_text(content: list[str], idx: int, input_data: dict, state: dict):

    LANG = st.session_state["language"]
    TEXT_DICT = text_dict[LANG][SERVICE_NAME]

    new_val = st.text_area(
        TEXT_DICT["edit_text"][1],
        content[idx]["post_content"],
        height=200,
        max_chars=1000,
    )

    with stylable_container(
        "social_media_generation_submit_edit",
        css_styles=cta_btn,
    ):
        submitted = st.button(TEXT_DICT["edit_text"][2])
    if submitted:
        with st.spinner(TEXT_DICT["edit_text"][3]):
            content[idx]["post_content"] = new_val
            ai_generator = SMCGenerator.get_post_text_eval_generator(
                settings=Settings(load_env=True)
            )
            data_chain = copy.deepcopy(input_data)
            data_chain["post_content"] = content[idx]["post_content"]
            try:
                result = ai_generator.invoke(data_chain)
                state.pop("post_scores", None)
                state.pop("image_outputs", None)
            except Exception as exc:
                print(exc)
                st.warning(text_dict[LANG]["code_utils"][0])
                st.stop()
            content[idx].update(result)
            st.rerun()

Steps To Reproduce

My app is pretty big and complex, I cannot share it directly the full source code

Expected Behavior

After the rerun, modal closes normally and page is normally refreshed, so the content looks the same as in the first screen

Current Behavior

Modal sometimes after it is closed, opens the app again in the modal

Is this a regression?

Debug info

Additional Information

No response

github-actions[bot] commented 1 month ago

If this issue affects you, please react with a 👍 (thumbs up emoji) to the initial post.

Your feedback helps us prioritize which bugs to investigate and address first.

Visits

lukasmasuch commented 1 month ago

@TheDjaangoo Thanks for reporting this issue. I believe this issue was solved recently (in PR https://github.com/streamlit/streamlit/pull/8798). Can you try it again with the most recent version?

TheDjaangoo commented 1 month ago

@LukasMasuch I am currently on holidays, once I am back, I will check and write here. Thanks for the hint and quick reply. Cheers!

kmcgrady commented 2 weeks ago

I believe we fixed this, so I am going to close it. @TheDjaangoo feel free to let us know if there's any issues.