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

Deploying Streamlit with Streamlit Community Cloud

So far in this book, we have focused on Streamlit app development, from creating complex visualizations to deploying and creating Machine Learning (ML) models. In this chapter, we will learn how to deploy these applications so that they can be shared with anyone with internet access. This is a crucial part of Streamlit apps as, without the ability to deploy a Streamlit app, friction still exists for users or consumers of your work. If we believe that Streamlit removes the friction between creating data science analysis/products/models and sharing them with others, then we must also believe that the ability to widely share apps is just as crucial as the ease of development.

There are three main ways to deploy Streamlit apps: through a product created by Streamlit called Streamlit Community Cloud, through a cloud provider such as Amazon Web Services or Heroku, or through Hugging Face via Hugging Face Spaces. Deploying on AWS and...

Technical requirements

This chapter requires access to Streamlit Community Cloud, which you can get access to by signing up for an account for free at https://share.streamlit.io/signup.

This chapter also requires a free GitHub account, which can be attained at https://www.github.com. A full primer on GitHub, along with detailed setup instructions, can be found in the section A quick primer on GitHub later in this chapter.

The code for this chapter can be found in the following GitHub repository: https://github.com/tylerjrichards/Streamlit-for-Data-Science.

Getting started with Streamlit Community Cloud

Streamlit Community Cloud is Streamlit’s answer to a fast deployment process and is certainly my first recommendation to deploy your Streamlit applications. When I discovered Streamlit in the summer of 2020, I remember deploying an app locally and loving the library, but then quickly being disappointed in having to use AWS to deploy my app. Then, the Streamlit team reached out to me and asked if I wanted to try out a product they were working on, which is now called Streamlit Community Cloud. I thought that there was no way that it was all that simple. We only need to push our code to a GitHub repository and point Streamlit to the said repository, and it takes care of the rest.

There are times when we care about “the rest,” such as when we want to configure the amount of storage space or memory available, but often, letting Streamlit Community Cloud handle deployment, resourcing, and sharing makes our development...

A quick primer on GitHub

GitHub and the language Git are collaboration tools for software engineers and data scientists that provide a framework for version control. We do not need to know everything about how they work to use Streamlit Community Cloud, but we need to be able to create our own repositories (which act like shared folders) and update them as we update our applications. There are two options for dealing with Git and GitHub: via the command line and via a product called GitHub Desktop.

Primarily in this book, so far, we have stayed on the command line, and this tutorial will stay there. However, if you would like to use GitHub Desktop instead, head over to https://desktop.github.com and follow along with the instructions provided there.

Now, use the following steps to get started with Git and GitHub on the command line:

  1. First, go to https://www.github.com and make a free account there.
  2. Then, we need to download the Git language onto our own...

Deploying with Streamlit Community Cloud

Now that all of our necessary files are in the GitHub repository, we have almost all that we need to deploy our application. You can use the following list of steps to deploy our application:

  1. When we deploy to Streamlit Community Cloud, Streamlit uses its own servers to host the app. Because of this, we need to explicitly tell Streamlit which Python libraries are required for our app to run. The following code installs a very helpful library called pipreqs and creates a requirements.txt file in the format we need for Streamlit:
    pip install pipreqs
    pipreqs .
    
  2. When we look at our requirements.txt file, we can see that pipreqs looked through all of our Python files, checked what we imported and used, and created a file that Streamlit can use to install the exact same versions of our libraries to prevent errors:

Figure 5.3: Requirements.txt

  1. We have a new file, so we need to also add it to...

Summary

In this chapter, we’ve learned how to get started with Git and GitHub on the command line, how to debug apps on Streamlit Community Cloud, how to use Streamlit Secrets to use private data on public apps, and how to deploy our apps quickly using Streamlit Community Cloud. This completes part one of this book! Congratulations on making it to this point. The next section will use all of part one as a building block for more advanced topics, such as more complicated formatting and beautification of our Streamlit apps and using valuable open-source community-built add-ons called Streamlit Components.

In the next chapter, we will cover beautifying Streamlit apps through themes, columns, and many more features.

Learn more on Discord

To join the Discord community for this book – where you can share feedback, ask questions to the author, and learn about new releases – follow the QR code below:

https://packt.link/sl

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