[Streamlit] tab과 col 명령어
2024. 1. 30. 10:47ㆍData Science/Study 자료
# _*_ coding:utf-8 _*_
import streamlit as st
import matplotlib.pyplot as plt
import plotly.graph_objects as go
import pandas as pd
import yfinance as yf
import seaborn as sns
def main():
st.title("hello")
with st.sidebar:
st.header("Sidebar")
day = st.selectbox("Select a day", ["Thur", "Fri", "Sat", "Sun"])
tips = sns.load_dataset("tips")
filtered_tips = tips[tips["day"] == day]
top_bill = filtered_tips["total_bill"].max()
top_tip = filtered_tips["tip"].max()
tab1, tab2, tab3 = st.tabs(['Total Bill','Tip','Size'])
with tab1:
st.header("Total Bill")
fig, ax = plt.subplots()
sns.scatterplot(data=filtered_tips, x = 'total_bill', y = 'tip',ax =ax)
st.pyplot(fig)
with tab2:
fig, ax = plt.subplots()
st.header("Tip Amounts")
sns.histplot(filtered_tips["tip"], kde=False, ax=ax)
st.pyplot(fig)
with tab3:
fig, ax = plt.subplots()
st.header("Table Sizes")
sns.boxplot(data=filtered_tips, x="sex", y="tip", ax=ax)
st.pyplot(fig)
col1, col2, col3 = st.columns([1,1,1]) # 시각화 안 넣는걸 추천
with col1:
st.metric("Top Bill", f"${top_bill:.2f}")
with col2:
st.metric("Top Tip", f"${top_tip:.2f}")
with col3:
st.write("col3")
if __name__ == "__main__":
main()
tab
tab1, tab2, tab3 = st.tabs(['Total Bill','Tip','Size'])
with tab1:
st.header("Total Bill")
fig, ax = plt.subplots()
sns.scatterplot(data=filtered_tips, x = 'total_bill', y = 'tip',ax =ax)
st.pyplot(fig)
with tab2:
fig, ax = plt.subplots()
st.header("Tip Amounts")
sns.histplot(filtered_tips["tip"], kde=False, ax=ax)
st.pyplot(fig)
with tab3:
fig, ax = plt.subplots()
st.header("Table Sizes")
sns.boxplot(data=filtered_tips, x="sex", y="tip", ax=ax)
st.pyplot(fig)
st.tabs()으로 각 tab을 만들어 준 뒤 with tab:으로 각 tab마다 데이터를 넣을 수 있다.
위 코드에서는 시각화 자료들을 넣어주었다.
col
col1, col2, col3 = st.columns([1,1,1]) # 시각화 안 넣는걸 추천
with col1:
st.metric("Top Bill", f"${top_bill:.2f}")
with col2:
st.metric("Top Tip", f"${top_tip:.2f}")
with col3:
st.write("col3")
st.columns([비율])로 칼럼을 만들 수 있다 .
with col: 로 데이터를 넣을 수 있다.
칼럼으로 시각화 표현은 추천 하지않는다.
'Data Science > Study 자료' 카테고리의 다른 글
뽐뿌 핫딜 데이터 크롤링/ csv파일 뽑기 코드 리뷰 (0) | 2024.02.01 |
---|---|
Api Crawling /Json 형식 데이터 단일/다중 수집 서울 열린데이터 광장 (0) | 2024.02.01 |
[Streamlit] sidebar활용 (0) | 2024.01.30 |
[Streamlit] st.write/ 마크다운 사용하기 (0) | 2024.01.29 |
내가 보려고 만드는 기본 리눅스 명령어 정리 (0) | 2024.01.23 |