Weird display behavior when loading data (not particularly large)

I am seeing some odd behavior with the multiselect widget that seems to be related to the delay it takes our data to load. You lose the selected values after selecting an item. I have recreated the issue using some static data and a small app (code below). If you move the multiselect above the load_data routine it behaves as expected (the majority of the time).

import streamlit as st

@st.cache()
def load_data():
    data = [True]*50000
    return data

a_widget = st.empty()

data_pd = load_data()

a_widget.multiselect("Apple", ['a','b','c'], key='key_apple')

Any insight?

Environment:

  • Linux (Ubuntu)
  • Python: 3.7.5
  • Streamlit: 0.65.2

Hey,
I was able to reproduce this error using your code. I’m using a Mac with

Python==3.8.5
Streamlit==0.65.2

Can you explain why you’re creating

a_widget = st.empty()

and then doing

a_widget.multiselect("Apple", ['a','b','c'], key='key_apple')

I tried the following and it works properly:

data_pd = load_data()
st.multiselect("Apple", ['a','b','c'], key='key_apple')

I’m not sure why your version is not working though

Sure. When designing the application it is nice to separate the layout from the control. To do this nicely I was using the st.empty() construct. Not sure if there is another way to accomplish the same idea.

I want to define the location for the multiselect in a layout section and then set the values after loading the data and filtering based upon other input fields.

I noticed the same when not using the st.empty() as well. We are able to manage but it makes the flow of the application much more difficult to keep organized.

Oh, I think this year they are going to come up with more features so we can customize the placement of objects. And you are right, st.empty() would be the way to go for separating the layout. I have used it before, although not with multi-select, so I’m not sure why it’s not working.