❄️
Data Flakes

Back

In this article, let’s explore what Streamlit is, how this works with Snowflake, and why you and your colleagues need to use this for data storytelling.

Features change from time to time with new features being added regularly, it is recommended that you review the documentation for the latest on what specific features are included with any of the Editions.

What is Streamlit?#

Streamlit is designed to simplify the creation of web applications for data science and machine learning projects. With a few lines of Python code, developers can build interactive user interfaces that facilitate data exploration and visualization. Streamlit’s declarative syntax allows for the straightforward transformation of data scripts into shareable web applications.

In the evolving landscape of data science and machine learning, the ability to rapidly develop and deploy interactive data applications is crucial. Streamlit, an open-source Python library, has emerged as a popular tool for creating such applications with minimal effort. By integrating Streamlit within Snowflake, a leading cloud-based data platform, developers can build, deploy, and share data applications directly within the Snowflake environment. This integration streamlines workflows, enhances security, and leverages Snowflake’s robust data processing capabilities.

Streamlit in Snowflake#

Integrating Streamlit within Snowflake enables developers to create and host Streamlit applications directly on Snowflake’s Data Cloud. This integration eliminates the need to move data between platforms, ensuring that data remains secure and governed within Snowflake. Developers can leverage Snowflake’s compute resources to run Streamlit applications, facilitating seamless data processing and visualisation.

Advantages of Using Streamlit in Snowflake#

  • Unified Data Processing: Hosting Streamlit applications within Snowflake allows data processing and visualisation to occur in the same environment, reducing latency and complexity.​

  • Managed Infrastructure: Snowflake manages the underlying infrastructure for Streamlit applications, allowing developers to focus on application development without the burden of server maintenance.​

  • Security and Compliance: Data remains within Snowflake’s secure environment, benefiting from robust security features and compliance certifications.​

  • Scalability: Streamlit applications can scale with Snowflake’s compute resources, accommodating varying workloads and user demands.​

  • Integration with Snowflake Features: Streamlit applications can seamlessly integrate with Snowflake features like Snowpark, user-defined functions (UDFs), and stored procedures, enhancing their capabilities.

Creating and Deploying Streamlit Applications in Snowflake#

Features change from time to time with new features being added regularly, it is recommended that you review the documentation for the latest on what specific features are included with any of the Editions.

Prerequisites#

Before creating a Streamlit application in Snowflake, ensure the following:

  • Access Permissions: Appropriate roles and privileges to create and manage Streamlit applications within your Snowflake account.​

  • Virtual Warehouse: An active virtual warehouse to run the Streamlit application and execute queries.​

  • Snowsight Access: Access to Snowsight, Snowflake’s web interface, for development and deployment.

Steps to Create a Streamlit Application#

  1. Sign in to Snowsight: Log in to your Snowflake account and navigate to Snowsight.​

  2. Navigate to Streamlit: In the left navigation bar, select Projects > Streamlit.​

  3. Create a New Streamlit App: Click on + Streamlit App to initiate a new application.

  4. Configure Application Details:

    • App Title: Enter a unique name for your application.​

    • App Location: Choose the database and schema where the application will reside.​

    • App Warehouse: Select the virtual warehouse to run your application.​

  5. Develop the Application: Utilise the Streamlit editor in Snowsight to write your Python code. The editor provides auto-completion and documentation for Streamlit and Snowpark functions.​

  6. Run and Preview: Use the Run button to execute your application and preview it in the adjacent pane.​

  7. Manage Dependencies: If your application requires external Python packages, add them via the Packages option in the editor.​

  8. Save and Deploy: Once development is complete, save your application. It is now ready to be shared and accessed based on the assigned permissions.

Building Your Own Interactive Data Dashboard#

Consider a scenario where you want to build an interactive dashboard to visualise sales data stored in Snowflake.

Step 1: Prepare the Data#

  • Create the Database, Schema, and Table: Execute the following SQL commands in your Snowflake environment to establish the required structures:
-- Create a new database named 'sales_db'
CREATE DATABASE IF NOT EXISTS sales_db;

-- Create a new schema named 'sales_schema' within 'sales_db'
CREATE SCHEMA IF NOT EXISTS sales_db.sales_schema;

-- Create a table named 'sales_data' within 'sales_schema'
CREATE TABLE IF NOT EXISTS sales_db.sales_schema.sales_data (
    sale_id INT AUTOINCREMENT PRIMARY KEY,
    sale_date DATE,
    region STRING,
    product STRING,
    quantity INT,
    revenue FLOAT
);
sql
  • Insert Sample Data into the Table: After creating the table, populate it with sample sales data using the following INSERT INTO statements:
-- Insert sample data into 'sales_data' table
INSERT INTO sales_db.sales_schema.sales_data (sale_date, region, product, quantity, revenue) VALUES
    ('2025-04-01', 'North', 'Product A', 10, 250.00),
    ('2025-04-02', 'South', 'Product B', 5, 125.00),
    ('2025-04-03', 'East', 'Product C', 8, 200.00),
    ('2025-04-04', 'West', 'Product D', 12, 300.00),
    ('2025-04-05', 'North', 'Product E', 7, 175.00);
sql

Step 2: Create the Streamlit Application#

In Snowsight, create a new Streamlit application named SalesDashboard.​

Step 3: Develop the Application#

In the Streamlit editor, write the following code:

Thing To Consider:#

  • Permissions: Verify that your Snowflake user role has the necessary privileges to create databases, schemas, tables, and to insert data.​

  • Warehouse Selection: Assign an appropriate virtual warehouse in Snowflake to handle the compute resources required for running the Streamlit application and executing queries.

Conclusion#

Integrating Streamlit within Snowflake empowers developers to create interactive data applications directly within the data cloud, streamlining workflows and enhancing data-driven decision-making. By leveraging Snowflake’s robust security features and scalable infrastructure, organisations can ensure their applications are both secure and performant. Adopting best practices such as effective caching strategies, managing dependencies, and optimising resource usage will further enhance application efficiency. Embracing Streamlit in Snowflake enables teams to rapidly develop and deploy data applications, fostering a more agile and informed business environment.

Disclaimer

The information provided on this website is for general informational purposes only. While we strive to keep the information up to date and correct, there may be instances where information is outdated or links are no longer valid. We make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability, or availability with respect to the website or the information, products, services, or related graphics contained on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk.