Trigger Empty Call on a Button Itself

So I have the following streamlit code inside my TopicGenerator class. It shows the topics retrieved from my backend server. I want to be able to regenerate the topics, so to do that I have a button that creates a new TopicGenerator class. I have also created all my elements within self.empy(), so that when the “Regenerate” button is pressed, everything gets removed:

        with self.container.container():
            self.selected_topic ="Select a topic", self.topics, + self.seed)
            if self.selected_topic:
            if st.button("Regenerate"):
                new_data = initial_response(seed=key_button_topic)
                st.session_state["topic_generator"] = TopicGeneration(new_data,
            if st.button("Choose Topic"):

This gives me an error right away:


And another one after (probably when my initial_response method finishes calling, the server takes about 10sec to respond):

Guessing my issue is with trying to delete the button that is itself calling the empty method…?

Hi @kongyiji_Peng

The error that you’re encountering is due to To fix this error, please pass a unique key argument to st.button which indicates that the key parameter in st.button() is being assigned a redundant key name during the iteration.

To resolve this, you’ll have to assign it a unique key name, for example, you can use something like key=f"button_{i}"

Hope this helps!

Best regards,

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