See screenshots towards the end of this post for before (none) and after (6)
I have a sidebar with expanders that represent categories. Clicking each “label” expands down and shows the items below it. I need to show the “number” of selected stories in the label.
I instantiate the st.expander like this:
expander_selected_stories = st.expander(
label=f"({st.session_state.selected_story_count}) Selected Stories")
Once that is done, I then call a function that loads the stories, generates the button under the expander (with) and this all works great. I verified that the count is returning, but the expander’s use of the session state variable isn’t updating until a page refresh.
Adding st.rerun() at various levels is causing a cascading rerun to happen and I have to exist the terminal app (ctrl+c)
with expander_selected_stories:
st.session_state.selected_story_count = self.load_selected_stories()
if I do an st.write immediately after this line, it reflects the number
write = st.write(st.session_state.selected_story_count)
So basically… label uses a session state variable in it, some stuff happens, and that label should update and reflect the new value… in this case the number of stories under that ‘category’
Before: (There are already 6 stories under the this ‘label’ by this point - initialized
After Page Refresh:
I need to be able to draw the component and have this number update. Also another feature is that people can change what a stories’ category is making it to where these counts could change quite a bit dynamically.