Update April 5:@st.experimental_fragment was released in Streamlit 1.33!
Hi everyone!
The Streamlit team is excited to share st.experimental_fragment, a new feature released in Streamlit 1.33 that provides a whole new level of flexibility and control for your apps.
@st.experimental_fragmentis a new decorator that turns any function into a “fragment” that can run independently of the wider page. Whenever an input widget inside the fragment changes, only the fragment reruns. This app introduces the feature and some common use cases.
A quick example
with st.spinner("Doing a slow thing"):
time.sleep(2)
@st.experimental_fragment # Just add the decorator
def simple_chart():
st.write("When you move the slider, only the chart updates")
val = st.slider("Number of bars", 1, 20, 4)
st.bar_chart(np.random.default_rng().random(val))
simple_chart()
This new decorator will turn any function into a Streamlit container that can run independently of the wider page.
It will also include a run_every= kwarg that allows you to automatically rerun the function and update the app every N seconds.
Want to learn more?
View the demo app for more use cases and examples.
Check out the docs article and API reference for more details. We’ll be adding more tutorials and examples in the coming days.
I placed a copy of streamlit-1.30.0-py2.py3-none-any.whl in my .streamlit folder and then did pip install streamlit-1.30.0-py2.py3-none-any.whl from that folder. Now when I the command streamlit --version I can see that it is now using Streamlit, version 1.30.0
When I try to run the Simple example code however, I get AttributeError: module 'streamlit' has no attribute 'partial'
Thanks @ferdy ! I agree, it looks like a slightly different issue. Will investigate. Not sure we will fix it for the whl file but it’s a good case to test for the final version!
This is the most useful feature that immediately improved my app efficiency and adoption. Please release ASAP! Thanks for your advise and help, @mliu !
Ticket Stream - Live Events Search Application Built with Streamlit → Powered by Ticketmaster
Whether you’re planning a trip, looking to catch the next big game, or can’t wait for the next visit to your favorite venue featuring live local bands, you can find it all here with instant access to live event listings wherever you go!
I found an issue where the partial decorator is very inconsistent with normal operation. If an element on a partial-rerun is not rendered after an update, it will not be removed in the diff and will remain on the page. Here is a super simple script to reproduce:
import streamlit as st
@st.partial
def main():
toggle = st.toggle('This toggle is bugged')
if toggle:
st.header('You should see "Toggle ON"')
else:
st.header('You should NOT see "Toggle ON"')
if toggle:
st.header('Toggle ON')
main()
When you remove the decorator, it works as expected. When you keep the decorator, the “Toggle ON” header will be rendered after you turn the toggle on and off again.