Blog Post and codes related to this video - medium.com/@avra42/streamlit-python-tips-how-to-avoid-your-app-from-rerunning-on-every-widget-click-cae99c5189eb
Superb man.... Seriously was dying to solve this issue. I got to know. But after this 6 mins video its so crystal clear. First should have come to YT instead of Google and docs You made it simple and clean. Thanks a lot for all these videos. One day they will scale to 1 million views. As all of these are so valuable and lifesaver
Hey Jorge , Thank you so much for this comment . Please keep on showering this love and support . And make sure to leave your feedbacks and suggestions. It will help me improve further. Stay in touch 🤗
This kind of comments are always very motivating for me to keep on creating more contents. I’m glad that it worked for you and also thanks for the affirmation that this old code is still 💪🏽 and working . Stay in touch 🤗
Amazing! I searched for solution for hours. Thank god I came acorss your medium article and this video. Simple and easy way to deal with the session problem. Thank you so much dude
Very informative video 😁 I am currently working on with streamlit, and I can't wait to implement these infos.. Thanks 😁 I also would like to see if you can make buttons that after you click, it can call other python scripts from other page into the current page.. Thank you in advance 😁
Hey thank you for your feedback. I’m glad that you liked this video. Your suggestion seems interesting, can you please elaborate further with an use case may be ? Thanks . Let’s stay in touch and please always feel free to share your feedbacks :)
Hi Avra, Thank you for sharing your knowledge with us. BTW, what application do you use for drawing your diagrams? It looks like hand-written, but I guess it is not.
Hi , there can be number of ways to implement such functionality. ATM - what comes to my mind is like - the select all check box , has an on click function - which swaps the value of other check boxes ( the other check boxes got it’s value stored in session state ) . In short - look for the implementation of session state and on click function . Hope this helps .
If we're want to run only part of code after clicking the widget , and that part of code uses the variables of other part of code that we don't want to rerun , then what should we do?
If I understood you correctly, wrapping those part of code within a Cache functions would do the trick. st.cache() or st.experimental_memo(). You can refer to the last part of my Blog Post where I mentioned about this - medium.com/@avra42/streamlit-python-tips-how-to-avoid-your-app-from-rerunning-on-every-widget-click-cae99c5189eb I hope this solves, otherwise apologies but please mention an use-case, which will help me to understand your question better. Stay In touch and let me know :)
As always great tutorial. Isbit possible to do the user authentication again but with session state included as well as st. Experimental params? Would be good to mesh these together. Thanks anyway!
Hi that’s indeed a great suggestion ! I’m planning to review few more Streamlit Components which covers user authentication. I’ll update you once I finish that . Stay in touch :)
Thanks for an excellent tutorial, however I am still struggling with how to store pyplots in session_state. As whenever i update any widget, my rendered image reloads again, even when its the same image. I have tried storing pyplot instance in sessions but its still not working, any idea how do I avoid that?
Hi! Amazing video, but for me it's not working. I've a multipage app and in one page I want to implement a neasted button. I have something like: if "Run PK Analysis" not in st.session_state: st.session_state["Run PK Analysis"] = False if st.button("Run PK Analysis", key="pk_button") or st.session_state['Run PK Analysis']: st.session_state['Run PK Analysis']=True with st.spinner("Building graphs..."): time.sleep(5) if 'df_result' in st.session_state: #code if st.button("PK interpretation", key="inter"): # Display PK interpretation content here st.write("PK interpretation content goes here." elif 'df_upload' in st.session_state: #code when I press second button ('pk interpretation') the page is refreshing... Could you help me?
I have a table and for that table i have added filters with buttons. When the button is clicked the whole app is rerunning. I have tried session.state also. Please help me on this
Hey, I'm having some issues initializing the session_state. Even though I initialise it the same way as you did, or as a classic dictionary it doesn't seem to recognize it and I get an error. Do you have any idea what the issue is?
Hey Thanks for your feedback. What's the error ? if you follow the exact lines, it shouldn't . Please check your Streamlit version. How about referring to the doc once , docs.streamlit.io/library/api-reference/session-state Do let me know, stay in touch :)
@@Avra_b Yeah I followed the same lines as you did. The error was: AttributeError: st.session_state has no attribute "load_state". Did you forget to initialize it? I should have the latest streamlit version since I downloaded it this week, but just in case how would I check the exact version? And which version would be necessary? Anyways thanks for your quick reply!
@@HarhanDerMann So, yeah it's because of the initialisation. Please refer to 04:35 of the video. There I refer to the Initialization part . Apologies, I'll update Time-Stamp for quick scrolling. Otherwise, you can check the Blog Post as well - medium.com/@avra42/streamlit-python-tips-how-to-avoid-your-app-from-rerunning-on-every-widget-click-cae99c5189eb If the problem still persist let me know. Cheers.
@@HarhanDerMann Okay, let's try with Streamlit's documentation code. Does that work for you ? Can you please send me link to your GitHub repo otherwise.
Hi @Igor , thanks for your feedback. I would like to understand more clearly this issue , can you please provide me with your use case ? As far as it goes, the video mainly indicates the workaround with the widgets active state. Data loading at every run can be ignored as well, for that wrapping within a function is necessary ( mentioned in the blog post )
It’s a trade I would say . We get the ease of development and prototyping quickly , trading with such inefficient state of widgets. There are frameworks nice niceGUI / Reflex / Solara - better in dealing with it