Sidebar not updating on re-run

Hello - I am using variables to display information in my sidebar. The variables are called out of st.session_state, and everything seems to run smoothly initially.

I also have a button in the sidebar that changes the variables stored in the st.session_state. When I click the button everything displayed in the main page updates, but the variables in the side bar do not. I have to click a radio button (also in the sidebar) to force it to refresh itself. After I do this, the variables in the side bar do update appropriately.

Any idea what is going on here? In my code, the commands to display the variables in the sidebar do appear before the code for the button, but I don’t think that should matter.

Thanks very much

Edit I put the code that effects the state into a call back function that the button now calls, with the intent that this code would run before the page is re-run. No change in functionality from what I describe above.

1 Like

Hi @7GS,

Would it be possible to get our hands on the code for a review?


Thanks for the reply - the code is a mess right now and in that mess it actually started updating properly. I have to clean it up and if the problem comes back I will post the code.

1 Like

Sounds good! I look forward to it! :slight_smile:


So I ended up fixing the display update problem by putting my code into a callback function and using on_click in my button arguments. However, now that callback function seems to be getting executed unexpectedly, not just when that button clicks. For example, when I use a toggle a radio button menu on the site it actually executes the on_click callback function for the button.

Are there any past threads about call back functions being unexpectedly run that you know of?

My callback function, which should only be getting called by a specific button, seems to be getting called any time any widget changes state.

Could this be caused by the fact that actually using an unsupported version of python - 3.9?