๐ฆ ํ๋ก์ ํธ์์ ์ฌ์ฉํ Streamlit ์ ๋ฆฌ ๐ฆ
๋จ๊ธฐ๊ฐ์ ๋ฏธ๋ ํ๋ก์ ํธ๋ฅผ ํ๊ธฐ ์ํด Streamlit์ ์ฌ์ฉํ๊ธฐ๋ก ๊ฒฐ์ ํ๋ค.
๊ทธ๋์ Streamlit์ ๋ํด ์ ๋ฆฌํ๊ณ ์ ํ๋ค.

python ๊ธฐ๋ฐ ์คํ ์์ค ๋ผ์ด๋ธ๋ฌ๋ฆฌ
์ต์ํ์ ์ฝ๋๋ก Data Science ๋ฐ Machine Learning Model์ ์๊ฐํํ๊ณ , ๋์ ์ธ ์น ์ ํ๋ฆฌ์ผ์ด์
์ ๋น ๋ฅด๊ฒ ๊ตฌ์ถํ ์ ์๋๋ก ์ค๊ณ๋์๋ค.
๊ณต์ ํํ์ด์ง์ ์ ์ํ๋ฉด ์ค์น ๋ฐฉ๋ฒ์ ์ ์ ์์ ๋ฟ๋ง ์๋๋ผ ์ปค๋ฎค๋ํฐ๋ฅผ ํตํด ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ฐพ์ ์ ์๋ค.
๋ฏธ๋ฆฌ ๊ตฌ์ถํด๋ ๋ฏธ๋์ฝ๋ค์ ๊ฐ์ํ๊ฒฝ์์ streamlit์ ์ค์นํด ์ฌ์ฉํ๋ค.
pip install streamlit
streamlit์ด ์ ์์ ์ผ๋ก ์ค์น๋์ง ์๋ ๊ฒฝ์ฐ ๊ฐ์ํ๊ฒฝ์ ํ์ด์ฌ ๋ฒ์ ์ ํ์ธํ๊ธธ ๋ฐ๋๋ค. ํ์ด์ฌ ๋ฒ์ 3.8 ~ 3.11์์ ์ค์น ๊ฐ๋ฅํ๋ค.
python -V
ํ์ด์ฌ ๋ฒ์ ์ ์ ๋ช ๋ น๋ฌธ์ ์ ๋ ฅํ๋ฉด ํ์ธ ๊ฐ๋ฅํ๋ค.
streamlit hello
streamlit์ด ์ค์น๋์๋ค๋ฉด ์ ๋ช ๋ น๋ฌธ์ ์ ๋ ฅํด ์ ์์ ์ผ๋ก ์ค์น๋์ด์๋์ง ํ์ธ ๊ฐ๋ฅํ๋ค.
pip install --upgrade streamlit
๋, streamlit์ ์ต์ ๋ฒ์ ์ผ๋ก ์ ๋ฐ์ดํธ ํ ๋ค ์คํํ๋ ๊ฒ์ ์ถ์ฒํ๋ค.
streamlit run <py_file>
ํ์ด์ฌ ํ์ผ์ streamlit์ผ๋ก ์คํํ๋ฉด ํ์ด์ง๊ฐ ์คํ๋๋ฉด์ ๊ตฌํ๋ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ ์ ์๋ค.
import streamlit as st
streamlit์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ import ํด์ผํ๋ค.
st.title(<content>)
st.header(<content>)
st.subheader(<content>)
st.text(<content>) // ๋จ์ ํ
์คํธ
st.write(<content>) // ๋จ์ ํ
์คํธ, ๋งํฌ๋ค์ด ๋ฑ ๋ค์ํ๊ฒ ์ถ๋ ฅ
st.markdown(<content> // ๋งํฌ๋ค์ด ์ง์
st.button(<button_name>)
if st.button(<button_name>):
... // button์ด ๋๋ ธ์ ๋์ ๋์ ์ ์
st.radio(<radio_name>, (<options>))
ex.
select_items = st.radio("example", ("value1", "value2", "value3"))
// select_imtes๋ฅผ ์ ํํ์ ๋ ๊ฐ์ด ์ถ๋ ฅ๋๋๋ก ์ ์
if select_items == "value1":
st.write("select value1")
elif select_items == "value2":
st.write("select value2")
else:
st.write("select value3")
st.sidebar.selectbox('<bar_name>`, (<values>))
ex.
selectbox = st.sidebar.selectbox('์์ ๋ฐ์ค', ('A', 'B', 'C'))
col1, col2, col3 = st.beta_columns(3) // ๋ ์ด์์ ๋๋๊ธฐ
// ์ด ์ ์
with col1:
...
with col2:
...
with col3:
...
Github๋ฅผ ์ฌ์ฉํด public ์ ์ฅ์๋ฅผ ๋ง๋ค๊ณ , ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด ๋ฐฐํฌ๋ฅผ ์งํํ๋ค. git์ pushํ๋ฉด ๋ฐฐํฌ๊ฐ ์งํ๋๊ธฐ ๋๋ฌธ์ ๋ณ๊ฒฝ ์ฌํญ์ ๋น ๋ฅด๊ฒ ์ ์ฉํ๊ณ , ์ฌ๋ฐฐํฌํ ์ ์๋ค๋ ์ ์ด ์ข์๋ค.
์ด๋ฏธ์ง ์ถ์ฒ
์ฐธ๊ณ -streamlit๊ณผ python_version
์ฐธ๊ณ -streamlit ์ค์น
์ฐธ๊ณ -streamlit ๋ฌธ๋ฒ