python==3.10.2
streamlit==1.34.0
I need to display dynamically created rows within the fragment. Each row is wrapped in the container. Each fragment rerun doesn’t clear out the containers created with the prior run.
full sample code below
When I select 5 rows, I get 5 containers, but after I slide down to 1 row, these containers do not get cleared.
import streamlit as st
cnt_top = st.container(height=100, border=True)
cnt_top.write("TOP")
cnt_slider = st.container()
cnt_rows = st.container(height=300, border=True)
@st.experimental_fragment
def draw_rows(container_slider_empty, container_rows_empty):
row_count = container_slider_empty.slider("Number of rows", 1, 5, 1)
row_container = container_rows_empty.container()
with row_container:
for idx in range(row_count):
with st.container(height=50, border=True):
st.write(idx)
draw_rows(cnt_slider.empty(), cnt_rows.empty())
It works fine with i.e. dividers, when I use st.divider() instead of st.container() in the loop, I get the expected number of dividers.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.