예 - 단일 페이지 Streamlit 앱

주의

이 기능은 AWS 및 Microsoft Azure 상업 리전 의 계정에서 사용할 수 있습니다. AWS PrivateLink 는 지원되지 않습니다.

이 항목에는 단일 페이지 Streamlit 앱의 기본 예가 포함되어 있습니다.

Streamlit 앱에서 Snowflake 데이터에 액세스하는 방법에 대한 자세한 내용은 예 - Streamlit in Snowflake 에서 Snowflake 데이터에 액세스하기 섹션을 참조하십시오. 다중 페이지 Streamlit 앱 생성에 대한 자세한 내용은 SQL을 사용하여 Streamlit 앱 만들기 섹션을 참조하십시오.

다음 예에서는 기본 Streamlit 앱을 보여줍니다.

# Import python packages
import streamlit as st
from snowflake.snowpark.context import get_active_session

# Write directly to the app
st.title("Example Streamlit App :balloon:")
st.write(
    """Replace this example with your own code!
    **And if you're new to Streamlit,** view
     our easy-to-follow guides at
    [docs.streamlit.io](https://docs.streamlit.io).
    """
)

# Get the current credentials
session = get_active_session()

# Use an interactive slider to get user input
hifives_val = st.slider(
    "Number of high-fives in Q3",
    min_value=0,
    max_value=90,
    value=60,
    help="Use this to enter the number of high-fives you gave in Q3",
)

#  Create an example dataframe
#  Note: this is just some dummy data, but you can easily connect to your Snowflake data
#  It is also possible to query data using raw SQL using session.sql() e.g. session.sql("select * from table")
created_dataframe = session.create_dataframe(
    [[50, 25, "Q1"], [20, 35, "Q2"], [hifives_val, 30, "Q3"]],
    schema=["HIGH_FIVES", "FIST_BUMPS", "QUARTER"],
)

# Execute the query and convert it into a Pandas dataframe
queried_data = created_dataframe.to_pandas()

# Create a simple bar chart
# See docs.streamlit.io for more types of charts
st.subheader("Number of high-fives")
st.bar_chart(data=queried_data, x="QUARTER", y="HIGH_FIVES")

st.subheader("Underlying data")
st.dataframe(queried_data, use_container_width=True)
Copy