Hi i have a program that is slow to execute (i think) and i would like to run it faster.
I already did: @st.cache_data to load data just once but i would like also to do that for graph etc. I mean i have some st.selectbox that change the output.
So my question is how to not run the code that follow if i do not change this st.selectbox option ? That could update my program and make it run faster
Or maybe somenone has better solution for me than the idea i have in my mind?
For example, i am displaying a dataframe based on selected period. It seems that the code is completely run whereas i did it already and it is just a display instruction.
I would like not to rerun the code
cols[0].write("**Classement des fonds selon Ranking :**")
choix_periode = cols[0].selectbox("Choix de la période pour affichage des résultats",
["1 an", "3 ans", "5 ans"],
index=0)
colonne_afficher = [col for col in classt.columns if choix_periode in col]
colonne_afficher = ["fund_name"] + colonne_afficher + ['Rank perf', 'Rank risque', 'Rank régularité', 'Rank']
cols[0].dataframe(classt
.loc[:, colonne_afficher]
.sort_values("Rank", ascending=False),
column_config={"fund_name": "Nom du fonds",
},
use_container_width=True,
hide_index=True
)
You mean that st.experimental_fragment is the right solution to me?
I need to do a function with code like that. That’s correct ???
@st.experimental_fragment
def data():
cols[0].write("**Classement des fonds selon Ranking :**")
choix_periode = cols[0].selectbox("Choix de la période pour affichage des résultats",
["1 an", "3 ans", "5 ans"],
index=0)
colonne_afficher = [col for col in classt.columns if choix_periode in col]
colonne_afficher = ["fund_name"] + colonne_afficher + ['Rank perf', 'Rank risque', 'Rank régularité', 'Rank']
cols[0].dataframe(classt
.loc[:, colonne_afficher]
.sort_values("Rank", ascending=False), # I can delete this line
column_config={"fund_name": "Nom du fonds",
},
use_container_width=True,
hide_index=True
)
I couldn’t tell for sure. It seems to be the answer to the question in the title: “How to rerun only a part of my program”.
What happened when you tried?
I think the effect of that would be that, when the user interacts with the selectbox, only the function data reruns, but not the rest of the code. But I have never used fragments.
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.