■ はじめに
https://dk521123.hatenablog.com/entry/2024/12/11/212315
でも触れたが、Streamlit in Snowflake を触ってみた。
目次
【1】Streamlit in Snowflake 【2】用途 【3】使用上の注意 1)接続がアクティブだとその分だけお金がかかる 2)機能制限あり 【4】Hello world
【1】Streamlit in Snowflake
* Snowflake に関わるアプリをPythonコードで、 インフラ設定なしに簡単に作成できる
https://docs.snowflake.com/ja/developer-guide/streamlit/about-streamlit
【2】用途
例えば、、、 * ユーザ管理する運用ツール などなど ちょっとしたらツールを作れる。
【3】使用上の注意
1)接続がアクティブだとその分だけお金がかかる
* 接続がアクティブである間はウェアハウスもアクティブのままになるため、 ウェアハウスが稼働した時間でクレジット加算されていく => 要するに金掛かる
2)機能制限あり
* 詳しくは、以下の公式ドキュメントに記載
https://docs.snowflake.com/ja/developer-guide/streamlit/limitations
【4】Hello world
https://docs.snowflake.com/ja/developer-guide/streamlit/create-streamlit-ui
[1] Snowflake の Web UIにログインする [2] 右ペインの [Project]-[Streamlit]を選択 [3] [+Steamlit App]ボタン押下 [4] 以下を入力し、「Create」ボタン押下 * App title: 任意(ここでは「Hello world」) * App location:使用したいDBとSchemaを選択 * App warehouse:使用したいウェアハウス (簡単ならアプリならサイズは軽めの方がいい) => 起動までしばし待つ => 勝手にサンプルができる
サンプル
https://docs.snowflake.com/ja/developer-guide/streamlit/example-single-page
# 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)
参考文献
https://ex-ture.com/blog/2024/08/15/create_sis_app/
関連記事
streamlit ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2024/12/11/212315