I’m processing some data a user uploads, but due to the size of the data it takes a while, so before processing, the user can select some options which help in cutting down the processing time:
st.sidebar.subheader("Options")
add_some_stuff, flag_other_stuff = False, False
if st.sidebar.checkbox("Analyze and add X"):
add_some_stuff = True
if st.sidebar.checkbox("Flag something):
flag_other_stuff = True
Then I use a button to delay the call to process the data until a user is done pressing buttons, adjusting sliders, etc etc.
if st.button('Process'):
with st.spinner("Processing..."):
#pass flags to processing function
df2 = process_data(df, cols, add_some_stuff, flag_other_stuff)
st.markdown("The first 50 rows:")
st.write(df2.head(50))
st.balloons()
This is working, but I’m wondering if there is a better way to wait for user input, then use that to call a function. The way I’m doing it currently I believe the app reruns with every checkbox ticked, its just that on rerun the app remembers the last value so this works for now, but doesn’t seem ideal.
I’m really liking streamlit, and appreciate the original intent - that when you move a slider or do something, stuff happens right away.
But with larger datasets, I want to be able to enter in different types of inputs, numbers, text, selecting from options, then use those to finally filter/process data.
What I’m really looking for is a way for all the input/select widgets to just return a value or state, and its stored in some global streamlit state dict, without streamlit re-running everything with every click.