streamlit4c / app.py
seawolf2357's picture
Update app.py
a3b9bb0 verified
raw
history blame
4.47 kB
import streamlit as st
import numpy as np
import pandas as pd
import time
# μ‚¬μ΄λ“œλ°” 타이틀
st.sidebar.title("접이식 메뉴")
# 메뉴 ν•­λͺ©κ³Ό ν•˜μœ„ ν•­λͺ© μ •μ˜
menus = {
"Display": ["Display text", "Display interactive widgets", "Display data", "Display media", "Display code", "Display progress and status"],
"Data": ["Connect to data sources", "Mutate data", "Placeholders, help, and options"],
"Control": ["Optimize performance", "Cache global resources", "Deprecated caching"],
"Layout": ["Columns", "Tabs", "Control flow"],
"Interactivity": ["Build chat-based apps", "Personalize apps for users"],
}
selected_menu = None
# 각 메뉴에 λŒ€ν•΄ μ‚¬μ΄λ“œλ°”μ— 접이식 메뉴 생성
for menu in menus:
with st.sidebar.expander(menu):
for sub_menu in menus[menu]:
if st.button(sub_menu, key=sub_menu): # κ³ μœ ν•œ keyλ₯Ό μ œκ³΅ν•˜μ—¬ 각 λ²„νŠΌμ„ ꡬ별
selected_menu = sub_menu
break
# μ„ νƒλœ 메뉴에 λ”°λ₯Έ λ™μž‘ κ΅¬ν˜„
if selected_menu:
st.header(f"Selected Menu: {selected_menu}")
if selected_menu == "Display text":
st.text('Fixed width text')
st.markdown('_Markdown_') # see #*
st.caption('Balloons. Hundreds of them...')
st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.write('Most objects') # df, err, func, keras!
st.write(['st', 'is <', 3]) # see *
st.title('My title')
st.header('My header')
st.subheader('My sub')
st.code('for i in range(8): foo()')
elif selected_menu == "Display interactive widgets":
# Interactive widgets
button_clicked = st.button('Hit me')
checkbox_checked = st.checkbox('Check me out')
radio_option = st.radio('Pick one:', ['nose', 'ear'])
selectbox_option = st.selectbox('Select', [1, 2, 3])
multiselect_options = st.multiselect('Multiselect', [1, 2, 3])
slider_value = st.slider('Slide me', min_value=0, max_value=10)
select_slider_option = st.select_slider('Slide to select', options=[1, '2'])
text_input = st.text_input('Enter some text')
number_input = st.number_input('Enter a number')
text_area = st.text_area('Area for textual entry')
date_input = st.date_input('Date input')
time_input = st.time_input('Time entry')
file_uploader = st.file_uploader('File uploader')
color_picker = st.color_picker('Pick a color')
# 주어진 μ½”λ“œ 쀑 μ‹€ν–‰λ˜μ§€ μ•Šκ±°λ‚˜ μ»¨ν…μŠ€νŠΈκ°€ λˆ„λ½λœ 뢀뢄은 주석 μ²˜λ¦¬ν•˜κ±°λ‚˜ μƒλž΅ν–ˆμŠ΅λ‹ˆλ‹€.
# 예λ₯Ό λ“€μ–΄, `data` λ³€μˆ˜κ°€ μ •μ˜λ˜μ§€ μ•Šμ•˜μœΌλ―€λ‘œ `st.audio(data)`, `st.video(data)` 등은 μ‹€ν–‰ν•  수 μ—†μŠ΅λ‹ˆλ‹€.
# λ˜ν•œ, `st.data_editor`, `st.camera_input` 등은 Streamlit의 ν˜„μž¬ λ²„μ „μ—μ„œ μ§€μ›ν•˜μ§€ μ•ŠλŠ” κΈ°λŠ₯μž…λ‹ˆλ‹€.
# 'st.experimental_rerun()'κ³Ό 같은 μ‹€ν—˜μ  κΈ°λŠ₯은 Streamlit의 νŠΉμ • λ²„μ „μ—μ„œλ§Œ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
# 각 κΈ°λŠ₯을 μ‚¬μš©ν•˜κΈ° 전에 Streamlit λ¬Έμ„œλ₯Ό μ°Έκ³ ν•˜μ—¬ ν˜„μž¬ λ²„μ „μ—μ„œ μ§€μ›ν•˜λŠ”μ§€ ν™•μΈν•˜μ„Έμš”.
# 기타 κΈ°λŠ₯ κ΅¬ν˜„μ€ μ„ νƒλœ 메뉴에 따라 μœ μ‚¬ν•œ νŒ¨ν„΄μœΌλ‘œ μΆ”κ°€ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
st.write(slider_val)
st.slider('Pick a number', 0, 100, disabled=True)
st.dataframe(my_dataframe)
st.table(data.iloc[0:10])
st.json({'foo':'bar','fu':'ba'})
st.metric(label="Temp", value="273 K", delta="1.2 K")
st.image('./header.png')
st.audio(data)
st.video(data)
col1, col2 = st.columns(2)
col1.write('Column 1')
col2.write('Column 2')
# Three columns with different widths
col1, col2, col3 = st.columns([3,1,1])
# col1 is wider
# Insert containers separated into tabs:
>>> tab1, tab2 = st.tabs(["Tab 1", "Tab2"])
>>> tab1.write("this is tab 1")
>>> tab2.write("this is tab 2")
# Stop execution immediately:
st.stop()
# Rerun script immediately:
st.experimental_rerun()
st.help(pandas.DataFrame)
st.get_option(key)
st.set_option(key, value)
st.set_page_config(layout='wide')
st.experimental_show(objects)
st.experimental_get_query_params()
st.experimental_set_query_params(**params)
with st.spinner(text='In progress'):
time.sleep(10)
st.success('Done')
# Show and update progress bar
bar = st.progress(50)
time.sleep(10)
bar.progress(100)
st.balloons()
st.snow()
st.toast('Mr Stay-Puft')
st.error('Error message')
st.warning('Warning message')
st.info('Info message')
st.success('Success message')
st.exception(e)