Reader small image

You're reading from  Streamlit for Data Science - Second Edition

Product typeBook
Published inSep 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781803248226
Edition2nd Edition
Languages
Concepts
Right arrow
Author (1)
Tyler Richards
Tyler Richards
author image
Tyler Richards

Tyler Richards is a senior data scientist at Snowflake, working on a variety of Streamlit-related projects. Before this, he worked on integrity as a data scientist for Meta and non-profits like Protect Democracy. While at Facebook, he launched the first version of this book and subsequently started working at Streamlit, which was acquired by Snowflake early in 2022.
Read more about Tyler Richards

Right arrow

Helpful mini-functions with streamlit-extras

I have personally been a part of the Streamlit data product team since the beginning of 2022, and that work unsurprisingly centers around creating Streamlit apps about the business that is Streamlit. The team creates dozens of apps for dozens of business partners, and as a part of that work has created dozens of helper functions that make it more fun and efficient to create Streamlit apps.

Every team has functions like these. At Streamlit, it is encouraged to open-source as much of your work as possible, so we decided to turn these functions into a Python package and release it out to the community.

For example, we had a problem where users of our apps would accidentally just select one date in a date range, and then the entire app would not run correctly. In response to this, we built a mandatory date range picker that will not run the app until two dates are selected! It can be used like this.

from streamlit_extras.mandatory_date_range import...

Finding more components

These components are a tiny percentage of all the components the Streamlit community has created, and by the time you may be reading this, I am sure the number of components out there will be dramatically higher. The best place to find new and interesting components is on either the Streamlit website at https://streamlit.io/gallery?type=components&category=featured or the discussion forums at https://discuss.streamlit.io/tag/custom-components.

When you find a component that you think is interesting, try it out by downloading it with pip as we did earlier, and read enough documentation to get started!

Summary

At this point, I hope you feel very comfortable downloading and using Streamlit Components, which you have learned about here, as well as comfortable with finding new Streamlit components created by the community. You should really understand how to find, download, and use Streamlit components to bolster the apps that you build.

In the next chapter, we will dive more deeply into deploying your own Streamlit apps with a cloud provider such as Amazon Web Services (AWS), or other services like HuggingFace!

Deploying Streamlit with Hugging Face

Hugging Face offers an entire suite of products focused on machine learning and is especially used by machine learning engineers and folks in the natural language processing space. It gives developers the ability to easily use pre-trained models through its transformers library (which we already used!) but also create products that let developers host their own models, datasets, and even their own data apps through a product called Hugging Face Spaces. You can think of a Space as a place to deploy an app on the Hugging Face infrastructure, and it is quite easy to get started.

For this chapter, we’ll deploy the same Hugging Face app that we created in Chapter 4. We can deploy any of our Streamlit apps on Hugging Face, but I thought it would be more fitting to deploy that one!

To start, we need to go to https://huggingface.co/spaces and click the button that says Create new Space.

Figure 8.1: Hugging Face login

After...

Deploying Streamlit with Heroku

Heroku is a Platform as a Service owned by Salesforce, optimized as a generic compute platform that you can use for everything from websites to APIs to Streamlit apps. Because of this, you have many more options with Heroku than with either Streamlit Community Cloud or Hugging Face Spaces, but getting started takes more effort.

Please note that Heroku has no free tier, so if you do not want to follow along (or if you are already happy with Streamlit Community Cloud or Hugging Face Spaces), feel free to just skip to the next chapter! The reason Heroku is included in this book is that I wanted to provide an option that had more capacity, supported the most recent Streamlit versions without much branding, and was easy to use. Heroku is the best platform on those metrics, so I’ll cover it below!

To deploy our Streamlit apps on Heroku, we need to do the following:

  1. Set up and log in to Heroku.
  2. Clone and configure our local...

Summary

This has been by far the most technical of our chapters so far, so congratulations on making it through! Deploying applications is notoriously difficult and time-consuming, and requires skills from software engineering and DevOps, along with often requiring experience with version control software (such as Git) and UNIX-style commands and systems. This is part of the reason why Streamlit Community Cloud is such a crucial innovation, but in this chapter, we have learned how to push the edge of Streamlit deployment by renting our own virtual machines and deploying apps on Hugging Face Spaces and Heroku. We have also learned how to figure out what the right deployment strategy is before starting out, which will save hours or days of work (nothing is worse than finishing the deployment of an app and finding out you need to use another platform!).

Next, we’ll move on to learning how to query from databases inside our Streamlit apps.

Learn more on Discord

To join...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Streamlit for Data Science - Second Edition
Published in: Sep 2023Publisher: PacktISBN-13: 9781803248226
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.
undefined
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

Author (1)

author image
Tyler Richards

Tyler Richards is a senior data scientist at Snowflake, working on a variety of Streamlit-related projects. Before this, he worked on integrity as a data scientist for Meta and non-profits like Protect Democracy. While at Facebook, he launched the first version of this book and subsequently started working at Streamlit, which was acquired by Snowflake early in 2022.
Read more about Tyler Richards