■ write 함수에서 DataFrame 객체를 사용해 대화형 테이블를 만드는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
import streamlit as st import pandas as pd @st.cache_data def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame st.title("Uber pickups in NYC") loadingDataText = st.text("Loading data...") dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) loadingDataText.text("Done! (using st.cache_data)") st.subheader("Raw data") st.write(dataFrame) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을
더 읽기
■ 단일 페이지 앱을 만드는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
import streamlit as st import pandas as pd import numpy as np @st.cache_data def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame st.title("Uber pickups in NYC") loadingDataText = st.text("Loading data...") dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) loadingDataText.text("Done! (using st.cache_data)") if st.checkbox("Show raw data"): st.subheader("Raw data") st.write(dataFrame) st.subheader("Number of pickups by hour") histogramArrayTuple = np.histogram(dataFrame["date/time"].dt.hour, bins = 24, range = (0, 24)) histogramValueNDArray = histogramArrayTuple[0] st.bar_chart(histogramValueNDArray) hour = st.slider("hour", 0, 23, 17) filteredDataFrame = dataFrame[dataFrame["date/time"].dt.hour == hour] st.subheader("Map of all pickups at %s:00" % hour) st.map(filteredDataFrame) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ map 함수에서 slider 객체의 선택 값으로 필터링한 데이터로 지도를 그리는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
import streamlit as st import pandas as pd import numpy as np @st.cache_data def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame st.title("Uber pickups in NYC") dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) hour = st.slider("hour", 0, 23, 17) filteredDataFrame = dataFrame[dataFrame["date/time"].dt.hour == hour] st.subheader("Map of all pickups at %s:00" % hour) st.map(filteredDataFrame) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install
더 읽기
■ bar_chart 함수를 사용해 히스토그램 차트를 그리는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
import streamlit as st import pandas as pd import numpy as np @st.cache_data def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame st.title("Uber pickups in NYC") dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) st.subheader("Number of pickups by hour") histogramArrayTuple = np.histogram(dataFrame["date/time"].dt.hour, bins = 24, range = (0, 24)) histogramValueNDArray = histogramArrayTuple[0] st.bar_chart(histogramValueNDArray) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ @cache_data 데코레이터를 사용해 함수에서 반환 데이터를 캐시하는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
import streamlit as st import pandas as pd @st.cache_data def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame st.title("Uber pickups in NYC") loadingDataText = st.text("Loading data...") dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) loadingDataText.text("Done! (using st.cache_data)") st.subheader("Raw data") st.write(dataFrame) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ subheader 함수를 사용해 서브 헤더 문자열을 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.title("Uber pickups in NYC") st.subheader("Number of pickups by hour") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ title 함수를 사용해 제목 문자열을 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.title("Uber pickups in NYC") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ image 함수를 사용해 이미지를 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.image("./blueberries.jpg") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다. blueberries.jpg
■ sidebar 변수에서 markdown 함수를 사용해 마크다운 문자열을 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.markdown("# Main page 🎈") st.sidebar.markdown("# Main page 🎈") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을
더 읽기
■ markdown 함수를 사용해 마크다운 문자열을 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.markdown("# Main page 🎈") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ 멀티 페이지 앱을 만드는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.markdown("# Main page 🎈") st.sidebar.markdown("# Main page 🎈") |
▶ ./pages/page1.py
|
import streamlit as st st.markdown("# Page 1 ❄️") st.sidebar.markdown("# Page 1 ❄️") |
▶ ./pages/page2.py
|
import streamlit as st st.markdown("# Page 2 🎉") st.sidebar.markdown("# Page 2 🎉") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install
더 읽기
■ connection 함수를 사용해 POSTGRESQL 데이터베이스 연결을 만드는 방법을 보여준다. ▶ ./.streamlit/secrets.toml
|
[connections.posgreSQL] type="sql" dialect="postgresql" username="user1" password="password1" host="127.0.0.1" port=5432 database="test" |
※ postgreSQL : 연결명 ※ postgresql : 데이터베이스 타입
더 읽기
■ SqlConnection 클래스의 query 메소드를 사용해 데이터를 조회하는 방법을 보여준다. ▶ ./.streamlit/secrets.toml
|
[connections.posgreSQL] type="sql" dialect="postgresql" username="user1" password="password1" host="127.0.0.1" port=5432 database="test" |
※ postgreSQL : 연결명 ※ postgresql : 데이터베이스 타입
더 읽기
■ scatter_chart 함수를 사용해 SCATTER 차트를 그리는 방법을 보여준다. ▶ main.py
|
import streamlit as st import pandas as pd import numpy as np if "df" not in st.session_state: st.session_state.dataFrame = pd.DataFrame(np.random.randn(20, 2), columns = ["x", "y"]) st.header("Choose a datapoint color") color = st.color_picker("Color", "#FF0000") st.divider() st.scatter_chart(st.session_state.dataFrame, x = "x", y = "y", color = color) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ divider 함수를 사용해 분리선을 추가하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.header("Choose a datapoint color") st.divider() color = st.color_picker("Color", "#ff0000") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ color_picker 함수를 사용해 색상을 선택하는 방법을 보여준다. ▶ main.py
|
import streamlit as st color = st.color_picker("색상", "#ff0000") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ header 함수를 사용해 헤더 문자열을 표시하는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.header("Choose a datapoint color") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ session_state 변수를 사용해 세션 상태를 관리하는 방법을 보여준다. ※ session_state 변수의 타입은 streamlit.runtime.state.session_state_proxy.SessionStateProxy 클래스이다. ▶ main.py
|
import streamlit as st if "counter" not in st.session_state: st.session_state.counter = 0 st.session_state.counter += 1 st.header(f"This page has run {st.session_state.counter} times.") st.button("Run it again") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.2 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.2 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※
더 읽기
■ text 함수를 사용해 텍스트를 만드는 방법을 보여준다. ▶ main.py
|
import streamlit as st for i in range(5): st.text(f"텍스트 {i + 1}") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ empty 함수를 사용해 플레이스 홀더를 만드는 방법을 보여준다. ▶ main.py
|
import time import streamlit as st emptyDeltaGenerator = st.empty() for i in range(100): emptyDeltaGenerator.text(f"Iteration {i + 1}") time.sleep(0.1) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ progress 함수를 사용해 진행바를 만드는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
import time import streamlit as st "Starting a long computation..." emptyDeltaGenerator = st.empty() progressDeltaGenerator = st.progress(0) for i in range(100): emptyDeltaGenerator.text(f"Iteration {i + 1}") progressDeltaGenerator.progress(i + 1) time.sleep(0.1) "...and now we\"re done!" |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ radio 함수를 사용해 라디오 버튼을 만드는 방법을 보여준다. ▶ main.py
|
import streamlit as st option = st.radio( "Sorting hat", ("Gryffindor", "Ravenclaw", "Hufflepuff", "Slytherin") ) st.write(f"You are in {option} house!") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ button 함수를 사용해 버튼을 만드는 방법을 보여준다. ▶ main.py
|
import streamlit as st st.button("Press me!") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ columns 함수를 사용해 앱 레이아웃을 제어하는 방법을 보여준다. ▶ main.py
|
import streamlit as st leftDeltaGenerator, rightDeltaGenerator = st.columns(2) leftDeltaGenerator.button("Press me!") with rightDeltaGenerator: option = st.radio( "Sorting hat", ("Gryffindor", "Ravenclaw", "Hufflepuff", "Slytherin") ) st.write(f"You are in {option} house!") |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install streamlit 명령을 실행했다.
■ sidebar 변수에서 selectbox/slider 함수를 사용해 사이드바에 선택 박스와 슬라이더를 만드는 방법을 보여준다. ▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
import streamlit as st # 사이드바에 선택 박스를 추가한다 : option = st.sidebar.selectbox( "How would you like to be contacted?", ("Email", "Home phone", "Mobile phone") ) st.write(option) # 사이드바에 슬라이더를 추가한다. value = st.sidebar.slider( "Select a range of values", 0.0, 100.0, (25.0, 75.0) ) st.write(value) |
▶ requirements.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
altair==5.3.0 attrs==23.2.0 blinker==1.8.2 cachetools==5.3.3 certifi==2024.6.2 charset-normalizer==3.3.2 click==8.1.7 gitdb==4.0.11 GitPython==3.1.43 idna==3.7 Jinja2==3.1.4 jsonschema==4.22.0 jsonschema-specifications==2023.12.1 markdown-it-py==3.0.0 MarkupSafe==2.1.5 mdurl==0.1.2 numpy==2.0.0 packaging==24.1 pandas==2.2.2 pillow==10.3.0 protobuf==5.27.1 pyarrow==16.1.0 pydeck==0.9.1 Pygments==2.18.0 python-dateutil==2.9.0.post0 pytz==2024.1 referencing==0.35.1 requests==2.32.3 rich==13.7.1 rpds-py==0.18.1 six==1.16.0 smmap==5.0.1 streamlit==1.36.0 tenacity==8.4.1 toml==0.10.2 toolz==0.12.1 tornado==6.4.1 typing_extensions==4.12.2 tzdata==2024.1 urllib3==2.2.2 watchdog==4.0.1 |
※ pip install
더 읽기