Examples of Streamlit session state and callbacks in a data labelling tool I made.

Data labelling tool built with Streamlit
Image by the author.
import streamlit as st# set variables in session state
st.session_state.projects = [
'Boring Project', 'Interesting Project'
]
st.session_state.current_project = st.radio(
'Select a project to work with:',
st.session_state.projects,
)
def fetch_data(project_name: str, row_index: int):
""" A simple example function to fetch data. """
dbs = {
'Boring Project': [...],
'Interesting Project': [...],
}
return dbs[project_name][row_index] # output can be any form
if 'current_project' in st.session_state:
row_index = st.session_state.get('row_index', 0)
data = fetch_data(st.session_state.current_project, row_index)
# examples to update row index
if st.button('Next', key='next_data'):
st.session_state.row_index += 1
if st.button('Previous', key='previous_data'):
st.session_state.row_index -= 1
def submit_add_project(project_name: str):
""" Callback function during adding a new project. """
# display a warning if the user...

Continue reading: https://towardsdatascience.com/advanced-streamlit-session-state-and-callbacks-for-data-labelling-tool-1e4d9ad32a3f?source=rss—-7f60cf5620c9—4

Source: towardsdatascience.com