Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Web App Development Made Simple with Streamlit

You're reading from  Web App Development Made Simple with Streamlit

Product type Book
Published in Feb 2024
Publisher Packt
ISBN-13 9781835086315
Pages 350 pages
Edition 1st Edition
Languages
Author (1):
Rosario Moscato Rosario Moscato
Profile icon Rosario Moscato

Table of Contents (23) Chapters

Preface 1. Part 1: Getting Started with Streamlit
2. Chapter 1: Getting to Know Streamlit – A Brief Overview 3. Chapter 2: Setting Up the Python Coding Environment 4. Chapter 3: Exploring Streamlit’s Features and Functionality 5. Part 2: Building a Basic Web App for Essential Streamlit Skills
6. Chapter 4: Streamlit Essentials – Configuring the Environment, Managing Packages, and More 7. Chapter 5: Organizing and Displaying Content with Columns, Expanders, and NLP Techniques 8. Chapter 6: Implementing NLP Techniques for Text Analysis and Processing in Streamlit 9. Chapter 7: Sharing and Deploying Your Apps on the Cloud Using Streamlit Share 10. Part 3: Developing Advanced Skills with a Covid-19 Detection Tool
11. Chapter 8: Advanced Environment Setup and Package Management for Building an AI-Powered Web App 12. Chapter 9: Optimizing Streamlit Web App UX with Customization and UI Features 13. Chapter 10: Utilizing Pretrained Models to Create Specialized and Personalized Web Applications 14. Chapter 11: Deploying and Managing Complex Libraries on Streamlit Share 15. Part 4: Advanced Techniques for Secure and Customizable Web Applications
16. Chapter 12: Smart File Uploading – Advanced Techniques for Professional Web Applications 17. Chapter 13: Creating a Secure Login and Signup Process for Web Applications 18. Chapter 14: Customizing Pages, Personalizing Themes, and Implementing Multi-Pages 19. Chapter 15: Enhancing Web Apps with Forms, Session State, and Customizable Subdomains 20. Chapter 16: Takeaways and Conclusion 21. Index 22. Other Books You May Enjoy

Enhancing Web Apps with Forms, Session State, and Customizable Subdomains

In Streamlit, forms, Session State, and customizable subdomains are all features that allow for more advanced customization and functionality in web applications.

Forms allow users to create interactive forms within their Streamlit web app that can be used to collect user input and perform actions based on a specific group of inputs. Forms can contain a variety of input elements, such as text fields, drop-down menus, and checkboxes.

Session State is a feature that allows users to store and persist data across different sessions of their web app. This can be useful for storing user preferences or app settings.

Finally, customizable subdomains allow users to create a custom subdomain for their Streamlit app that can be useful for branding or creating a more memorable URL (instead of using the standard anonymous URL proposed automatically).

In this chapter, we’re going to cover the following main...

Technical requirements

What are forms and when and why do we use them?

Streamlit forms is a feature that allows you to create interactive web forms in your Streamlit apps. These forms enable you to collect user input through different widgets such as textboxes, selects, checkboxes, and more. When a user submits a form, Streamlit automatically captures the input values and makes them available to your Python code.

Using Streamlit forms is simple. You can define the form boundaries with st.form() and add widgets within it. Streamlit provides a variety of input components that make it easy for users to enter information such as text input, number input, and so on. This integration with Python eliminates the need for manual form handling.

Streamlit forms offer customization options to improve the user experience. You can add labels, default values, and tooltips to guide users. Additionally, you can control a form’s layout and style to match your app’s design.

Form submission is always...

What is Session State and when do we use it?

Streamlit was launched in 2019, and statefulness was a little problem for quite a long time since states weren’t managed natively. However, starting from version 0.8.4, things changed, and the official claim (https://blog.streamlit.io/session-state-for-streamlit/) was as follows:

You can now store information across app interactions and rerun!

To be honest, that claim is really perfect because it conveys everything about sessions. Streamlit’s Session State feature offers an efficient and sophisticated approach to session management. This feature enables the storage of variables across multiple reruns, facilitates the creation of interactive events on input widgets, and allows the use of callback functions to manage these events effectively.

The robust capabilities of Session State enhance the development of various applications. These capabilities include the following:

  • Integrating widgets that are interdependent...

What are customizable subdomains and what possibilities do they offer?

We have already deployed two applications on Streamlit Cloud: the NLP App and the COVID-19 Detection Tool. So, we are quite familiar with the process, and even how to solve problems arising due to big files or a need for unconventional libraries.

Upon deploying our application on Community Cloud, it is assigned an automatically generated subdomain, which is structured based on our GitHub repository. This subdomain, unique to our application, serves as a means to share the app with others. Nevertheless, the default subdomain can often be cumbersome and not particularly user-friendly. For instance, a subdomain such as the following may not be easily memorable:

https://streamlit-demo-self-driving-streamlit-app-8jya0g.streamlit.app

To enhance shareability and recognition, we have the option to establish a custom subdomain. This customization allows the subdomain to better represent the content of our app, our...

Summary

In this chapter, we covered some topics that can really increase the level of our web applications.

First of all, we saw what forms are and how to use them, discovering that having independent groups of widgets inside our web apps can make a big difference. All we need to do is define these forms and include some widgets inside them, using a button to trigger the widgets. Even the button is customizable since it can be included in the form or placed outside it.

Further, we learned that Session State is an incredibly powerful weapon in our hands. At last, we can persist the values of our variables, and this opens up an incredible scenario of use cases to us. Moreover, thanks to callbacks, we can decide what to do when a user interacts with our widgets, calling back fully customized functions that completely match our needs.

Finally, by customizing the subdomains of our deployed web applications, we achieved two targets: we made them much easier to remember and we gave...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Web App Development Made Simple with Streamlit
Published in: Feb 2024 Publisher: Packt ISBN-13: 9781835086315
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}