Force redraw of an earlier element

Hi there,

How do I force redraw of an earlier element. e.g.:

# experiment selector
experiment_names = df.experiment_name.unique()
experiment = st.selectbox('Experiment:',

# delete button
if st.button('Delete Experiment'):
    df = df[df.experiment_name != experiment]
    experiment = df.experiment_name.unique().tolist()

Hi @aristogeiton, you can redraw certain objects with some code like this one:

import streamlit as st
x = st.empty()"initial text")
if st.checkbox("Check to redraw"):"redraw")

In this case, you can obtain a placeholder with st.empty and write that placeholder depending on your flow. Unfortunately, not all objects are re-drawable. Redrawable objects are of the DeltaGenerator type and are contained in this file:

Note that not all objects are of the DeltaGenerator are redrawable though, Widgets are not. Examples of redrawable objects are: text, markdown, code, json, title, header, subheader, error, warning, info, success.

We are working at making this better and improve the documentation on this. I added a documentation request:

Let me know if you need more questions and more help for your use case.


1 Like

Thank you Matteo, that answer was helpful for me too. The DeltaGenerator seems to work also for e.g. select boxes.

import streamlit as st
x = st.empty()
x.selectbox("Initial select", ["a", "b", "c"])
if st.checkbox("Check to update selectbox"):
    x.selectbox("New select", ["d", "e", "f"])

But how can I retrieve the selected option from the new select box? x is now a DeltaGenerator rather than a string as in the standard case (not using st.empty).


(this is my first post in a forum like this, maybe you should always post a new question in a new thread? sorry in that case)