I am new to streamlit and I am trying to build an app with the following functionality:
- Select / drop some features and train a bunch of models. I created
st.sidebar.multiselect to drop features and using
form_submit_buttonto create a button to initiate training.
- After training, print the scores for all the models.
- After looking at the scores, select few models (using
st.sidebar.multiselect) and plot a graph between actual and predicted for only those models.
I wrote the following code:
drops = st.sidebar.multiselect('Pick any items you want to remove from the analysis.', df.keys()) form = st.form(key = 'myform', clear_on_submit = False) submit = form.form_submit_button('Train Models') if submit: scores, features, predictions, y_test, data_raw, scaler, lr, ridge, lasso, tree, forest, gbr, lin_svr = main_analysis(df, target_name, drops) st.write('Here are the scores from the models that were run:') df_scores = pd.DataFrame.from_dict(scores) df_scores st.write('Based on the model scores above, pick the models you want to use to continue this analysis.') best_models = st.sidebar.multiselect('Pick top model scores:',df_scores.keys())
When I run the code, I see a submit button (Train Models), I am able to train models and get the scores after I click on the submit button. When I try to select few models with
st.sidebar.multiselect, everything is getting reset and reverting to ‘Train Models’ stage. The selections are not stored.
I tried the same thing using
st.button, it does the same thing.
How do I store the selections after using a submit button?
Any help is greatly appreciated