How to reset selectbox options after submitting

Summary

How to reset selectbox options after submitting

Steps to reproduce

state = df[‘CV_State_Clean’].unique().tolist()
CV_State_Clean = col8.selectbox(‘Select State’,state)

add code here

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.

Links

  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

You can set (or reset) widgets by directly accessing their value via their key in session state.

import streamlit as st

st.selectbox('Select:',['Please Select',1,2,3],key='selection')

def reset():
    st.session_state.selection = 'Please Select'

st.button('Reset', on_click=reset)

I have a video about changing widgets through session state here: Session State Introduction

1 Like