4 Streamlit's execution model

 

This chapter covers

  • Creating apps that require maintaining state between page updates
  • Troubleshooting your apps effectively
  • The all important st.session_state and st.rerun
  • Streamlit's execution model

In the last two chapters, you've gotten your feet wet with Streamlit by building two fully-functional apps: a password checker and a unit converter. You've learned the basics of Streamlit's syntax and how to create interactive elements. But what happens behind the scenes when you run a Streamlit app? Understanding this is key to building more complex applications.

This chapter delves into the heart of Streamlit's execution model, where we'll explore how to manage an app's state.

This chapter also takes a slightly different approach than the previous ones. While we'll still build a practical application – a daily to-do list app – the primary focus is on equipping you with troubleshooting skills. We'll intentionally introduce some bugs into the app to simulate real-world situations where things might not go according to plan. By following along and fixing these issues, you'll gain a deeper understanding of Streamlit's inner workings and how to debug your own apps effectively.

4.1 A more complex app: Daily to-dos

 
 
 

4.1.1 Stating the concept

 
 
 

4.1.2 Defining the requirements

 

4.1.3 Visualizing the user experience

 
 

4.1.4 Brainstorming the implementation

 
 
 

4.2 Implementing and troubleshooting our app

 
 
 

4.2.1 Displaying the task list

 
 
 

4.2.2 Enabling actions

 
 

4.3 How Streamlit executes an app

 
 
 
 

4.3.1 Frontend and server

 
 
 
 

4.3.2 App re-runs

 
 
 

4.3.3 Applying this to our app

 
 
 
 

4.4 Persisting variables across re-runs

 

4.4.1 st.session_state

 
 
 

4.5 Completing our app

 
 
 

4.5.1 Adding session state

 
 
 

4.5.2 Wiring up the "Delete" buttons

 
 
 

4.5.3 What's happening behind the scenes

 
 
 

4.5.4 Triggering re-runs automatically

 
 

4.5.5 Wiring up the checkboxes

 
 

4.5.6 An infinite re-run loop

 
 

4.5.7 Preventing the infinite re-run

 
 
 
 

4.5.8 Adding the completion progress indicator

 
 
 
 

4.6 Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest