forked from streamlit/streamlit-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
40 lines (30 loc) · 1014 Bytes
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Modified from Johannes Rieke's example code
import streamlit as st
from snowflake.snowpark import Session
st.title('❄️ How to connect Streamlit to a Snowflake database')
# Establish Snowflake session
@st.cache_resource
def create_session():
return Session.builder.configs(st.secrets.snowflake).create()
session = create_session()
st.success("Connected to Snowflake!")
# Load data table
@st.cache_data
def load_data(table_name):
## Read in data table
st.write(f"Here's some example data from `{table_name}`:")
table = session.table(table_name)
## Do some computation on it
table = table.limit(100)
## Collect the results. This will run the query and download the data
table = table.collect()
return table
# Select and display data table
table_name = "PETS.PUBLIC.MYTABLE"
## Display data table
with st.expander("See Table"):
df = load_data(table_name)
st.dataframe(df)
## Writing out data
for row in df:
st.write(f"{row[0]} has a :{row[1]}:")