Hi @abhi and Randy
Thanks for getting back to me.
Completely understand the focus you have.
To elaborate on what I need, Iāve prepared a minimal example. This example is a bit contrived, as the layout here looks fine, but when you have a large form and the interdependent widgets are somewhere in the middle, the problem is more real. But I hope the example here makes it more clear what I mean. I am interested in the functionality from example 1 with the layout from example 2 below.
import streamlit as st
import pandas as pd
import numpy as np
@st.cache
def filter_df(df, column, min_value, max_value, default_min=0, default_max=100):
if min_value != default_min or max_value != default_max:
filter = (df[column] >= min_value) & (df[column] <= max_value)
df = df[filter]
return df
st.title("Example 1")
df = pd.DataFrame({"A" : np.arange(100), "B": np.arange(100), "C": np.arange(100)})
## With not so nice layout but right functionality
options = st.multiselect("Select columns", options=["A","B", "C"])
with st.form(key="example_1"):
sliders = {option : st.slider(option, min_value=0, max_value=100, value=(0,100)) for option in options}
st.form_submit_button("Submit")
# Here we apply filter from all sliders on the DF. This is potentially an expensive operation
# with large dfs, thus we want to use a form for the sliders
for column, (min_value, max_value) in sliders.items():
df = filter_df(df, column, min_value, max_value)
st.write(df)
st.title("Example 2")
df = pd.DataFrame({"A" : np.arange(100), "B": np.arange(100), "C": np.arange(100)})
## With nice layout but needs to "double click" submit
with st.form(key="example_2"):
options = st.multiselect("Select columns", options=["A","B", "C"])
sliders = {option : st.slider(option, min_value=0, max_value=100, value=(0,100)) for option in options}
st.form_submit_button("Submit")
# Here we apply filter from all sliders on the DF. This is potentially an expensive operation
# with large dfs, thus we want to use a form for the sliders
for column, (min_value, max_value) in sliders.items():
df = filter_df(df, column, min_value, max_value)
st.write(df)
Best,
Peter