Here I ave used text-input, selectbox and form_submit_button inside st.expermimental_fragment. And all of this is present inside a container.
Now when I am clicking this checked button it says “could not find fragment”. I dont know what i am missing, can anyone has any clue why this might be happening?? RuntimeError: Could not find fragment with id 33ceabc972d74023f8209621d7ce3d5e
Because of this error, my form is not getting form_submit_button and hence the following error.
# this is just an exact replica of the main problem that I am solving
import streamlit as st
def myfunc(): # this function is called from login page if login is successful
@st.experimental_fragment
def fragment(k):
with st.form(str(k)+"check"):
status_update_cols = st.columns(3)
comment = status_update_cols[0].text_input("Comment",key=str(k)+"comment")
call_type = status_update_cols[1].selectbox(label="Call Type:",options=["A","B","C"],key=str(k)+"calltype")
check = status_update_cols[2].form_submit_button("Checked")
def keywords(s,e):
count = 1
for i in range(s,e):
with st.container():
st.write(f"This is {i} container")
fragment(count)
count+=1
but = st.button("Click me",key="key")
but2 = st.button("Click me",key="key2")
if but:
keywords(0,5)
if but2:
keywords(0,5)
Decorator to turn a function into a fragment which can rerun independently of the full script.
When a user interacts with an input widget created by a fragment, Streamlit only reruns the fragment instead of the full script. If run_every is set, Streamlit will also rerun the fragment at the specified interval while the session is active, even if the user is not interacting with your app.
To trigger a full script rerun from inside a fragment, call st.rerun() directly. Any values from the fragment that need to be accessed from the wider app should generally be stored in Session State.
When Streamlit element commands are called directly in a fragment, the elements are cleared and redrawn on each fragment rerun, just like all elements are redrawn on each full-script rerun. The rest of the app is persisted during a fragment rerun. When a fragment renders elements into externally created containers, the elements will not be cleared with each fragment rerun. In this case, elements will accumulate in those containers with each fragment rerun, until the next full-script rerun.
Calling st.sidebar in a fragment is not supported. To write elements to the sidebar with a fragment, call your fragment funciton inside a with st.sidebar context manager.
Fragment code can interact with Session State, imported modules, and other Streamlit elements created outside the fragment. Note that these interactions are additive across multiple fragment reruns. You are responsible for handling any side effects of that behavior.
yes, its working fine here in this sample which I shared. But similar structure is not giving me desired result in my another code I have lots of containers and text inside them.
So I just wanted to know if my flow of code is correct or not with this sample. Am I doing aything wrong with fragments? And also please let me know when do we get fragment id not found error? That error is still not resolved… I have gone through the fragments documentation.
Yes, even I encountered the issue of fragment id not found. It’s not always replicable but the error is thrown while passing run_every parameter to experimental_fragment decorator!
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.