Bug ? with multiselect + rerun

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed?
    Locally

  2. Share the Streamlit and Python versions.
    Streamlit 1.39.0
    Python 3.9.18

I have a simple repro case for this.

Steps to reproduce:

  1. Run the simple app below
  2. Select a few columns in the multi-select
  3. Now click on “Rerun” button
  4. Now, you will see the multiselect is showing selections in the UI but thats just stale UI. Actually, the widget internally thinks it has nothing selected.
  5. Say Twing if you agree this is a bug
import streamlit as st
import pandas as pd 

if st.button('Rerun now'):
    st.rerun()

pdf = pd.DataFrame({
            'BusinessUnit': ['A', 'B', 'C', 'D'],
            'Category': ['SGA', 'Interest', 'Taxes', 'COGS'],
            'Grade': ['P', 'P', 'VIP', 'N']
        })

cols = st.multiselect('Select columns', list(pdf.columns), key='orchard')
if len(cols) == 0:
    st.write('No col selected')
for col in cols:
    st.write('Selected col = {}'.format(col))

It does look like a bug to me. Here is a simpler version that doesn’t need pandas.

import streamlit as st

if st.button('Rerun twice'):
    st.rerun()

selected = st.multiselect('Select options', options=["one", "two", "three"])
st.write(selected)

I can reproduce it with other input widgets too. They keep displaying whatever value they had when the button was pressed, but they return the default value instead.

1 Like

I kind of understand what is going on.

Since “rerun” is called before rendering the multiselect widget, streamlit simply marks it as “not rendered during last run”. So in the new run, it thinks the widget is stateless and hence associates its default value.

This can be easily verified by adding this line before the rerun. Though it looks crazy, when we assign the value, streamlit thinks “user” has touched this key, and so it maintains it in the “rerun” run.

st.session_state['orchard'] = st.session_state['orchard']

As counter-intuitive as that might look, that’s what always happen is not rendered in a rerun, so it makes complete sense to me. The actual issue is that the rendering of the widget doesn’t match that.

True, I agree with the semantics as well. The UI part needs an update.

Has this been lodged as a bug? how can I know when it is fixed so I can update the streamlit version in my installation?