streamlit
streamlit 파이썬 개발 시, 파일 분리하여 개발하는 방법
iminu
2022. 5. 20. 17:37
먼저 메인 파이썬 파일을 만들어 준다.
## 파일을 분리해서 만드는 앱 ###
import streamlit as st
from app9_about import run_about
from app9_eda import run_eda
from app9_home import run_home
from app9_ml import run_ml
def main():
st.title('파일 분리 앱')
menu = ['Home', 'EDA', 'ML', 'About']
choice = st.sidebar.selectbox('메뉴', menu)
if choice == menu[0]:
run_home()
elif choice == menu[1]:
run_eda()
elif choice == menu[2]:
run_ml()
elif choice == menu[3]:
run_about()
if __name__ == '__main__':
main()
그리고 from 모듈 import 함수로 다른 파일에 있는 함수를 불러온다.
아래는 app9_home파일이다.
import streamlit as st
from PIL import Image
def run_home():
st.subheader('홈 화면입니다.')
st.text('파일 분리 앱 실습하는 중')
img = Image.open('data2/image_03.jpg')
st.image(img)