I have a function:
@st.experimental_fragment(run_every=“30s”)
def plot_line_chart_v2
Multiple charts are being drawn using the above function is it poassible to set st.fragment programatically to true based on a condition.
Please suggest.
Thanks
I have a function:
@st.experimental_fragment(run_every=“30s”)
def plot_line_chart_v2
Multiple charts are being drawn using the above function is it poassible to set st.fragment programatically to true based on a condition.
Please suggest.
Thanks
Hi @Sai_SaiGraph,
Thanks for sharing this question!
There’s no direct way to set this dynamically because @st.experimental_fragment decorator is applied at function definition time and not during runtime.
You can work around this by defining 2 separate functions and using a condition to call the appropriate one. The functions could look like this:
@st.experimental_fragment(run_every="30s")
def plot_line_chart_v2_fragment():
df = get_data()
st.line_chart(df)
# Regular function
def plot_line_chart_v2():
df = get_data()
st.line_chart(df)
Hi @Sai_SaiGraph,
I don’t know if this helps, but I have something similar. For my case, I wanted a new container with some specific analysis to show if the user selects an item in one of my selectboxes.
@st.experimental_fragment
def user_activity_graph(dataframe):
"analysis to be performed"
return analysed_dataframe
Use in streamlit
product_list = st.multiselect(options=unique_product_list, label="Products", placeholder="Select product")
if product_list:
with st.container(border=True):
st.subheader('XXXXs')
user_activity_graph(users_activities_df)
So basically, this container will be shown only if an item is selected from the product_list.
Hope this helps.
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.
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.
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.
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.