다중 페이지 Streamlit 앱

이 항목에서는 다중 페이지 Streamlit 앱 의 예를 제시합니다. 다음 예에서는 다음 파일이 포함된 다중 페이지 Streamlit 앱을 보여줍니다.

  • 주 Streamlit 앱(streamlit_main.py): 이는 CREATE STREAMLIT 명령의 MAIN_FILE 속성에 값으로 제공하는 Streamlit 앱입니다. 이 파일은 Snowsight 에서 Streamlit 앱을 볼 때도 기본적으로 표시됩니다.

  • data_frame_demo.py: 애플리케이션의 데이터 프레임을 표시합니다.

  • plot_demo.py: 애플리케이션의 데이터 플롯을 표시합니다.

Streamlit in Snowflake 에서 여러 파일로 작업하는 방법에 대한 자세한 내용은 Snowsight 를 사용하여 Streamlit 앱 만들기 및 배포하기 섹션을 참조하십시오.

참고

Streamlit in Snowflake 에서 다중 페이지 앱을 호스팅하는 경우 URL 경로 이름 앞에는 /! 가 접두사로 붙습니다. 예를 들어 다중 페이지 앱에서 페이지의 상대 경로가 /page2 인 경우 Streamlit in Snowflake 의 상대 경로는 다음 URL 에 표시된 것과 같이 /!/page2 가 됩니다. https://app.snowflake.com/org/account_name/#/streamlit-apps/DB.SCHEMA.APP_NAME/!/page_2

streamlit_main.py

import streamlit as st st.title('Multi-page app demo') st.write('This is the landing page for the app. Click in the left sidebar to open other pages in the app') 
Copy

data_frame_demo.py

import streamlit as st # Write directly to the app st.title("Dataframe Demo App :balloon:") # Get the current credentials session = st.connection('snowflake').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

plot_demo.py

import time import numpy as np import streamlit as st from streamlit.hello.utils import show_code def plotting_demo(): progress_bar = st.sidebar.progress(0) status_text = st.sidebar.empty() last_rows = np.random.randn(1, 1) chart = st.line_chart(last_rows) for i in range(1, 101): new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0) status_text.text("%i%% Complete" % i) chart.add_rows(new_rows) progress_bar.progress(i) last_rows = new_rows time.sleep(0.05) progress_bar.empty() # Streamlit widgets automatically run the script from top to bottom. Because # this button is not connected to any other logic, it just causes a plain # rerun. st.button("Re-run") st.set_page_config(page_title="Plotting Demo", page_icon="📈") st.markdown("# Plotting Demo") st.sidebar.header("Plotting Demo") st.write(  """This demo illustrates a combination of plotting and animation with  Streamlit. We're generating a bunch of random numbers in a loop for around  5 seconds. Enjoy!""" ) plotting_demo() show_code(plotting_demo) 
Copy