Snowflake Streamlit Apps

Analysts often produce answers that colleagues want to explore on their own: filters, charts, and drop-down menus. Streamlit is a Python framework that turns a short script into an interactive web app. Streamlit in Snowflake runs those apps inside the platform, so data never leaves the secure environment.

The Idea in Simple Words

A spreadsheet shows numbers to one person at a time. A Streamlit app works like a small shop window for your data. Visitors pick a region from a menu, and the chart behind the glass changes instantly. The shop owner writes plain Python, and no web design skill is needed.

STREAMLIT IN SNOWFLAKE
======================

 +--------------------------------------------------+
 |                 SNOWFLAKE ACCOUNT                |
 |                                                  |
 |  +-------------+     +-----------------------+   |
 |  | Streamlit   |     | Tables and views      |   |
 |  | app (Python)|---->| queried by the app    |   |
 |  +------+------+     +-----------------------+   |
 |         |                                        |
 +---------|----------------------------------------+
           v
   Browser: menus, charts, tables
   (users sign in with Snowflake credentials)

Why Build Inside Snowflake

  • No separate server, hosting, or deployment pipeline.
  • Data stays inside the account, protected by existing roles.
  • Sharing works through role grants rather than public links.
  • Python and SQL live in the same place.

Creating an App in Snowsight

  1. Open Snowsight and choose Projects, and Streamlit.
  2. Select the plus button to create a new app.
  3. Name the app and choose a database, schema, and warehouse.
  4. Edit the sample code in the editor on the left.
  5. Watch the live preview on the right.

A Complete Example

import streamlit as st
from snowflake.snowpark.context import get_active_session

session = get_active_session()

st.title("Sales Explorer")

# Menu filled from a live query
regions = session.sql("SELECT DISTINCT region FROM sales_db.public.orders").to_pandas()
choice = st.selectbox("Choose a region", regions["REGION"])

# Query data for the chosen region
df = session.sql(f"""
    SELECT order_date, SUM(amount) AS revenue
    FROM sales_db.public.orders
    WHERE region = '{choice}'
    GROUP BY order_date
    ORDER BY order_date
""").to_pandas()

st.subheader(f"Daily revenue for {choice}")
st.line_chart(df, x="ORDER_DATE", y="REVENUE")
st.dataframe(df)

The get_active_session function returns a ready Snowpark session, so no login code appears. Each time a user changes a widget, Streamlit reruns the script from top to bottom and redraws the page.

Common Widgets

WIDGET                 PURPOSE
---------------------  ----------------------------------
st.selectbox           Pick one value from a list
st.multiselect         Pick several values
st.slider              Choose a number or range
st.date_input          Choose a date
st.button              Trigger an action
st.text_input          Type free text
st.metric              Show a headline number
st.bar_chart           Draw a bar chart
st.dataframe           Show a table

Performance and Cost

Each interaction runs queries on the app's warehouse. Caching avoids repeated work.

@st.cache_data(ttl=600)
def load_orders():
    return session.sql("SELECT * FROM sales_db.public.orders").to_pandas()

orders = load_orders()

The cached result lives for ten minutes. Use a small warehouse with a short auto-suspend setting, and limit rows pulled into the app.

Sharing and Security

Apps run with the app owner's role privileges in many setups, so viewers see what the owner role allows. Create a dedicated role for the app, grant it only the needed views, and share the app with chosen roles.

GRANT USAGE ON STREAMLIT sales_db.public.sales_explorer TO ROLE analyst_role;

Avoid placing raw personal data in views behind the app. Aggregated or masked views reduce risk.

A Practical Scenario

A regional sales director wants to compare store performance without waiting for an analyst. An analyst builds a Streamlit app with a region menu, a date range slider, and two charts. The director opens the app from Snowsight, picks a region, and sees revenue trends in seconds. Store managers use the same app with their own roles, and row-level security limits each manager to a single store. The analyst fixes a chart label in one minute and every user sees the update.

Frequently Asked Questions

Do users need Python knowledge?

Users interact with menus and charts in the browser. Only the app builder writes Python.

Can an app write data back to a table?

Apps can run INSERT or UPDATE statements through the session, and the role behind the app must hold the matching privileges.

Key Points

  • Streamlit turns a Python script into an interactive web app.
  • Streamlit in Snowflake hosts apps inside the account with no extra servers.
  • get_active_session supplies a ready connection to run queries.
  • Widgets such as selectbox and slider collect user choices.
  • Caching and small warehouses control cost.
  • Role grants decide who can open each app.