Summary
Hi there, In my application, I have two buttons: “Create” and “Edit.” These buttons are supposed to take the user to the next page by changing the session state but I need to click twice in order an action to accrue.
Steps to reproduce
Code snippet:
def main():
# Initialize session_state if it doesn't exist
if "page" not in st.session_state:
st.session_state.page = ""
st.session_state.selected = None # Add a session state for selected
if st.session_state.page == "edit":
table_name = st.session_state.selected # Use the saved selected value
edit_table = EditTable(table_name)
edit_table.show_ui()
if st.button('Back'):
st.session_state.page = ""
elif st.session_state.page == "create":
st.title("Create New Table")
FactTable()
if st.button('Back'):
st.session_state.page = ""
else:
# default is home page
home_instance = HomePage()
home_instance.generate_home_page()
if st.button('Edit Table'):
if home_instance.selected:
st.session_state.page = "edit"
st.session_state.selected = home_instance.selected[0]['Table Name'] # Save selected value to session_state
else:
#call to warning function that prints a warning
warning("Select a table to edit.")
if home_instance.created_button:
st.session_state.page = "create"
if __name__ == '__main__':
main()
Expected behavior:
I’m facing an issue where I have to click a button twice for the action to be triggered. It’s not necessary to click the same button twice; for example, I could click the “Edit” button once, nothing happens, then I click the “Create” button, and only then do I go to the edit page.
I’ve tried adjusting the order of the code because I know Streamlit reads from top to bottom each time, but the problem persists. Any assistance would be greatly appreciated!
Actual behavior:
After click on “Create” or “Edit” buttons -take the user to the next page by changing the session state (and current page the user click on the buttons from will be invisible)
Debug info
- Streamlit version: 1.22.0
- Python version: Python 3.7.13
- Using Conda? No
- OS version: mac os 12.6.3
- Browser version: Version 113.0.5672.126
Requirements file
streamlit
numpy
asyncio
pandas
streamlit-aggrid