Streamlit in Snowflake for data science and machine learning

OVERVIEW

Streamlit is an open-source Python library that is used for creating web applications for data science and machine learning. It allows data scientists and developers to turn data scripts into interactive web applications without requiring extensive web development experience.

KEY FEATURES

  •      Simplicity
  •      Rapid Development
  •      Interactive Widgets
  •      Data Integration
  •      Deployment

Streamlit in Snowflake

We can create apps that process and use data within Snowflake using Streamlit, all without transferring data or application code to another system. Creating Streamlit applications is a completely managed process. Snowflake manages the provisioning of the underlying compute and storage for apps and performs the work on the developer’s behalf. Applications use Snowflake stages to store files and data, and they operate on Snowflake warehouses.

Step by step guide to Create a Streamlit app by using Snowpark
Let’s create a simple Streamlit application.
• Sign in to Snowsight as a user with the CREATE STREAMLIT privilege on the schema in which you want to
create the app.
• In the left navigation bar, select Streamlit.
• Select + Streamlit.
• Create Streamlit App window will open.
• Enter a name for your app and Select Warehouse and App location (Database and Schema) where we want to create the Streamlit application.
• Click on Create

Picture1

On clicking the CREATE button, a side-by-side editor window will open. The left-hand side shows the application’s code while right hand side shows the output of the application.

Application Setup

Importing the required libraries, setting up the page configuration and gaining access to the current session.

Picture2

get_active_session returns the details of an active session,Altair is a python library for visualization.

Loading data

Now load and cache the data from COVID19_EPIDEMIOLOGICAL_DATA.PUBLIC.ECDC_GLOBAL and  COVID19_EPIDEMIOLOGICAL_DATA.PUBLIC.GOOG_GLOBAL                _MOBILITY_REPORT tables.

Picture3

Covid-19 cases by Country

Adding the functions of dropdown for country selection and Chart to visualise Covid-19 cases for the selected country.

Picture4

Google mobility by Country

Adding the functions to dropdown for country selection and Chart to visualise Change in google mobility by selected country.

Picture5

Application Components

Adding the functions to display the application’s header and to create a sidebar.

Picture6

Run the Application

To Run the application, Click the RUN button which is located at the top right corner.
Then the result will be shown as below in the snippet.

Picture7

To view the Covid cases or Change in Mobility,

Select Covid-19 Data or Google Mobility Data from the Sidebar.
Hence, by using the Streamlit app we can explore COVID-19 cases and change in Google Mobility data. It effectively manages large datasets to avoid message size limitations. Users can analyze data by country, visualize it in charts, and navigate through data using pagination.

 

Conclusion:

In summary, the integration of Streamlit with Snowflake offers a potent combination for developers and data professionals. This collaboration seamlessly integrates the simplicity of Streamlit’s rapid application development with the robust data warehousing capabilities of Snowflake. The result is a user-friendly and scalable solution that empowers users to effortlessly create interactive, visually appealing applications, making data-driven insights more accessible and impactful. Whether visualizing analytics or presenting dynamic dashboards, the Streamlit-Snowflake synergy accelerates development cycles and enhances the overall user experience, emphasizing the collaborative potential of user-centric frameworks and advanced data warehousing solutions.

Account Limitations:

Streamlit in snowflake has following limitations during preview

  • Your Snowflake account must be located in an Amazon Web Services (AWS) region.
  • Accounts in the following platforms/regions are not currently supported:
    • Google Cloud Platform (GCP).
    • Microsoft Azure.
    • Virtual Private Snowflake (VPS).
    • US government regions that support FedRAMP.
  • The combined length of your account name and organization name must be less than 41 characters and account name must be unique within your organization.

Reference:https://docs.snowflake.com/en/developer-guide/streamlit/about-streamlit

Cittabase Specializes in modernized data platform implementations and a Snowflake SELECT Partner. Feel free to reach out for any of your Snowflake implementations.