Dialog doesn't open a second time

I have a script that should open a dialog when the user clicks on a button. It works fine the first time the user clicks in the button, but after this, the dialog doesn’t open again if the user clicks on the button.

This is a screenshot of the dashboard, it displays containers with some text, links, and an image in columns. Interestingly, if the containers show fewer things (like only the images and nothing else), everything works as it should.

If I start clicking on the button to open the dialog many times, eventually the dialog opens, but only sometimes.

Script: mantium/dashboard/01_📖_Dashboard.py at main · diogovalentte/mantium · GitHub

Hey @diogovalentte, this issue might be related to st.dialog not opening when long st.code is displayed on page · Issue #9323 · streamlit/streamlit · GitHub as the symptoms you are describing sound familiar.
I have a PR open for this here.
If you are open for it, it would be great if you could install the PR’s wheel file: https://core-previews.s3-us-west-2.amazonaws.com/pr-9333/streamlit-1.37.1-py2.py3-none-any.whl and let me know whether your issue would be fixed by the PR as well :slightly_smiling_face:
I would test it myself with your application, but it looks like I would need to set some environment variables for API keys etc.

Thank you for the reply @raethlein. The PR’s wheel file works fine!

Is there a version of this but in version 1.34.0? For some reason, my app gets VERY slow when using streamlit > 1.34.0. So slow that my browser says that the site isn’t responding.

Great to hear that the issue would be solved by it! Thanks for testing it :slightly_smiling_face:
And sorry to hear that you are experiencing issues with Streamlit > 1.34.0
Unfortunately, we don’t backport this kind of fixes to older versions of the library.
Though, is there an easy way to run your app locally for me? I would be really interested in looking deeper into this performance issue.

The app depends on an API, which depends on a database. To run it all you need docker to start the DB and golang installed to start the API, and also set some environment variables. It’s a little complicated, so I can’t provide an easier way.

@raethlein I update the app’s repository readme to add better instructions on how to run the dashboard if you’re interested in testing it, as I couldn’t fix the performance issue alone: GitHub - diogovalentte/mantium: Mantium is a dashboard for tracking mangas from multiple source sites, like Manga Plus, Mangadex and ComicK.

The performance is bad only when there are more of these containers on the dashboard, and you have to add one by one to the dashboard. However, I can also upload my database volume with all set up, if you want.

1 Like

Awesome, thank you! I will give it a try tomorrow and circle back to you here :slightly_smiling_face:

1 Like

Alrighty, I got it running! Do you have an idea how many items would need to exist in order for me to see the performance degradation? If it is a lot, maybe sharing your db would be nice :slight_smile:

It’s better to use my db: 64.23 MB file on MEGA

Great, thank you! I think I have found when this started to happen! It looks like the CSS styling introduced in this PR is problematic. I will discuss it with the team and we should hopefully come up with a fix soonish! I’ll keep you posted.

1 Like

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

Hello,

I got several issues with st.dialog:

  1. Same issue as above. When a user click on X or outside of the modal, it won’t open again.
  2. st.rerun inside the decorated dialog function seems to rerun everything, not just the fragment. I can give an example if needed.

Here is my code for references:

import streamlit as st

from ai.assistants.chat import get_chat_assistant

from app.copilot.base import Streaming, clear_dialog, CONTAINER_HEIGHT


def set_auto_prompt(value):
    st.session_state.auto_prompt = value


@st.dialog(title="Copilot", width='large')
def copilot_messenger(**copilot_params):
    if 'auto_prompt' not in st.session_state:
        st.session_state.auto_prompt = None

    # Display the chat messages
    chat_container = st.container(height=CONTAINER_HEIGHT, border=False)

    with chat_container.container():  # Using the container
        st.markdown("Ask me anything.")
        st.markdown(":gray[EXAMPLE QUESTIONS]")

        # Define columns and example buttons
        cols = st.columns(2)
        cols[0].button(
            'What is Sharpe ratio?',
            key='ex-sharpe',
            on_click=set_auto_prompt,
            args=('What is Sharpe ratio?',),
            use_container_width=True
        )
        cols[1].button(
            'What is Sortino ratio?',
            key='ex-sortino',
            on_click=set_auto_prompt,
            args=('What is Sortino ratio?',),
            use_container_width=True
        )

        cols = st.columns(2)
        cols[0].button(
            'What is MFE?',
            key='ex-mfe',
            on_click=set_auto_prompt,
            args=('What is Maximum Favorable Excursion (MFE)?',),
            use_container_width=True
        )
        cols[1].button(
            'What is a frontier efficient?',
            key='ex-f-eff',
            on_click=set_auto_prompt,
            args=('What is a frontier efficient?',),
            use_container_width=True
        )

    # Instantiate the copilot object
    streaming = Streaming(get_chat_assistant, chat_container)

    # Input section
    cols = st.columns([4, 1, 1])
    with cols[0]:
        user_prompt = st.chat_input("Ask me anything...")

    with cols[1]:
        cleared = st.button(
            'Clear',
            key='clear-ai',
            use_container_width=True
        )
        if cleared:
            clear_dialog(chat_container)

    with cols[2]:
        canceled = st.button(
            'Cancel',
            key='cancel-ai',
            type='primary',
            use_container_width=True
        )
        if canceled:
            clear_dialog(chat_container)
            st.rerun()

    # Run copilot with the current prompt
    prompt = (
        user_prompt
        if st.session_state.auto_prompt is None
        else st.session_state.auto_prompt
    )

    streaming.run(prompt=prompt, **copilot_params)

    # Reset the prompt input
    st.session_state.auto_prompt = None

This should be fixed in the next version 1.39 which we will hopefully release this week (see this PR).

You can pass the scope argument to st.rerun like st.rerun(scope="fragment") to limit the rerun to the current fragment (which dialog uses under-the-hood).

1 Like

Thanks @raethlein

1 Like

@raethlein any news or somewhere for me to follow about the performance issue when >v1.34.0 I wrote about?

Hey @diogovalentte, I have had created a GitHub issue here for it a couple of weeks ago: Streamlit slows down with many nested blocks · Issue #9456 · streamlit/streamlit · GitHub

I had a discussion with @lukasmasuch and I believe he has a solution which isn’t too nice though, which is why he wanted to spend a little more time thinking about it. So, best to keep an eye on the GitHub issue which will get updated e.g. with a relevant PR etc.
Sorry that no fix made it into 1.39, but I hope 1.40 is the one!

1 Like