streamlit-server-state
streamlit-server-state copied to clipboard
NoSessionRerun and Fragment reruns
Adds NoSessionRerun, so you can do:
with no_session_rerun:
server_state['foo'] = bar
This will cause all sessions bound to 'foo' to be rerun except the session setting the value. The idea is that the session that sets the value already knows the value and does not require a rerun. This is also helpful to prevent circular updates.
Adds fragment reruns, so you can have specific fragments rerun when a certain key in the server_state is mutated. Like:
@st.fragment
def messages_fragment():
server_state.register_current_fragment_rerun(for_updates_to='messages')
with lock...:
st.write(server_state['messages'])
...
server_state['messages'] = server_state['messages'] + [message]
When the 'messages' array is updated it does not do a complete app rerun, but instead only reruns a specific fragment (in all sessions).