seawolf2357 commited on
Commit
6e8c858
Β·
verified Β·
1 Parent(s): 8c042f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -104
app.py CHANGED
@@ -1,106 +1,29 @@
1
  import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
- import matplotlib.pyplot as plt
5
- from PIL import Image
6
- import io
7
 
8
- # νŽ˜μ΄μ§€ μ„€μ •
9
- st.set_page_config(page_title="Streamlit UI Components", page_icon=":sparkles:")
10
-
11
- # 제λͺ©
12
- st.title("Streamlit UI Components μ˜ˆμ‹œ")
13
-
14
- # λΆ€μ œλͺ©
15
- st.header("μž…λ ₯ μ»΄ν¬λ„ŒνŠΈ")
16
-
17
- # ν…μŠ€νŠΈ μž…λ ₯
18
- text_input = st.text_input("ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”")
19
-
20
- # 숫자 μž…λ ₯
21
- number_input = st.number_input("숫자λ₯Ό μž…λ ₯ν•˜μ„Έμš”", min_value=0, max_value=100)
22
-
23
- # ν…μŠ€νŠΈ μ˜μ—­
24
- text_area = st.text_area("μ—¬λŸ¬ 쀄 ν…μŠ€νŠΈλ₯Ό μž…λ ₯ν•˜μ„Έμš”")
25
-
26
- # λ‚ μ§œ μž…λ ₯
27
- date_input = st.date_input("λ‚ μ§œλ₯Ό μ„ νƒν•˜μ„Έμš”")
28
-
29
- # μ‹œκ°„ μž…λ ₯
30
- time_input = st.time_input("μ‹œκ°„μ„ μ„ νƒν•˜μ„Έμš”")
31
-
32
- # 파일 μ—…λ‘œλ“œ
33
- uploaded_file = st.file_uploader("νŒŒμΌμ„ μ—…λ‘œλ“œν•˜μ„Έμš”", type=["png", "jpg", "jpeg", "txt", "csv"])
34
-
35
- # μŠ¬λΌμ΄λ”
36
- slider = st.slider("μŠ¬λΌμ΄λ”λ₯Ό μ‘°μ •ν•˜μ„Έμš”", 0, 100, 50)
37
-
38
- # μ…€λ ‰νŠΈλ°•μŠ€
39
- selectbox = st.selectbox("μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”", ["μ˜΅μ…˜ 1", "μ˜΅μ…˜ 2", "μ˜΅μ…˜ 3"])
40
-
41
- # λ©€ν‹°μ…€λ ‰νŠΈ
42
- multiselect = st.multiselect("μ—¬λŸ¬ μ˜΅μ…˜μ„ μ„ νƒν•˜μ„Έμš”", ["μ˜΅μ…˜ A", "μ˜΅μ…˜ B", "μ˜΅μ…˜ C"])
43
-
44
- # λΌλ””μ˜€ λ²„νŠΌ
45
- radio = st.radio("λΌλ””μ˜€ λ²„νŠΌμ—μ„œ μ„ νƒν•˜μ„Έμš”", ["선택 1", "선택 2", "선택 3"])
46
-
47
- # μ²΄ν¬λ°•μŠ€
48
- checkbox = st.checkbox("μ²΄ν¬λ°•μŠ€λ₯Ό μ„ νƒν•˜μ„Έμš”")
49
-
50
- # λ²„νŠΌ
51
- if st.button("ν΄λ¦­ν•˜μ„Έμš”"):
52
- st.success("λ²„νŠΌμ΄ ν΄λ¦­λ˜μ—ˆμŠ΅λ‹ˆλ‹€!")
53
-
54
- st.header("좜λ ₯ μ»΄ν¬λ„ŒνŠΈ")
55
-
56
- # ν…μŠ€νŠΈ 좜λ ₯
57
- st.write("여기에 ν…μŠ€νŠΈλ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€.")
58
-
59
- # λ°μ΄ν„°ν”„λ ˆμž„ 좜λ ₯
60
- df = pd.DataFrame({
61
- 'column 1': [1, 2, 3, 4],
62
- 'column 2': [10, 20, 30, 40]
63
- })
64
- st.dataframe(df)
65
-
66
- # 차트
67
- chart_data = pd.DataFrame(np.random.randn(20, 3), columns=['a', 'b', 'c'])
68
- st.line_chart(chart_data)
69
-
70
- # κ·Έλ¦Ό 좜λ ₯
71
- if uploaded_file is not None and uploaded_file.type.startswith("image/"):
72
- image = Image.open(uploaded_file)
73
- st.image(image, caption="Uploaded Image")
74
-
75
- # λΉ„λ””μ˜€ 좜λ ₯
76
- video_file = open('example.mp4', 'rb')
77
- video_bytes = video_file.read()
78
- st.video(video_bytes)
79
-
80
- # μ½”λ“œ 좜λ ₯
81
- code = '''def hello():
82
- print("Hello, Streamlit!")'''
83
- st.code(code, language='python')
84
-
85
- # 맡
86
- map_data = pd.DataFrame({
87
- 'lat': np.random.randn(10) + 37.76, # μƒŒν”„λž€μ‹œμŠ€μ½” μœ„λ„ μ£Όλ³€
88
- 'lon': np.random.randn(10) - 122.4 # μƒŒν”„λž€μ‹œμŠ€μ½” 경도 μ£Όλ³€
89
- })
90
- st.map(map_data)
91
-
92
- # 진행바
93
- import time
94
- progress_bar = st.progress(0)
95
- for i in range(100):
96
- time.sleep(0.1)
97
- progress_bar.progress(i + 1)
98
-
99
- st.header("차트 μ˜ˆμ‹œ")
100
-
101
- # λ§‰λŒ€ 차트
102
- fig, ax = plt.subplots()
103
- ax.bar(["A", "B", "C"], [10, 20, 15])
104
- st.pyplot(fig)
105
-
106
- # 주의: μ‹€μ œ μ½”λ“œ 싀행을 μœ„ν•΄μ„œλŠ” 'example.mp4' λΉ„λ””μ˜€ 파일이 ν•„μš”ν•©λ‹ˆλ‹€. ν•΄λ‹Ή 파일이 μ—†λ‹€λ©΄ λΉ„λ””μ˜€ κ΄€λ ¨ μ½”λ“œλ₯Ό 주석 μ²˜λ¦¬ν•˜κ±°λ‚˜ νŒŒμΌμ„ μ€€λΉ„ν•΄μ£Όμ„Έμš”.
 
1
  import streamlit as st
 
 
 
 
 
2
 
3
+ # μ‚¬μ΄λ“œλ°” 타이틀
4
+ st.sidebar.title("접이식 메뉴")
5
+
6
+ # 메뉴 ν•­λͺ©κ³Ό ν•˜μœ„ ν•­λͺ© μ •μ˜
7
+ menus = {
8
+ "A": ["A-1", "A-2", "A-3"],
9
+ "B": ["B-1", "B-2", "B-3"],
10
+ "C": ["C-1", "C-2", "C-3"],
11
+ "D": ["D-1", "D-2", "D-3"],
12
+ "E": ["E-1", "E-2", "E-3"],
13
+ }
14
+
15
+ # μ„ νƒλœ 메뉴λͺ…을 μ €μž₯ν•  λ³€μˆ˜
16
+ selected_menu = None
17
+
18
+ # 각 메뉴에 λŒ€ν•΄ μ‚¬μ΄λ“œλ°”μ— 접이식 메뉴 생성
19
+ for menu in menus:
20
+ with st.sidebar.expander(menu):
21
+ for sub_menu in menus[menu]:
22
+ if st.button(sub_menu, key=sub_menu): # κ³ μœ ν•œ keyλ₯Ό μ œκ³΅ν•˜μ—¬ 각 λ²„νŠΌμ„ ꡬ별
23
+ selected_menu = sub_menu
24
+
25
+ # μ„ νƒλœ 메뉴λͺ… 좜λ ₯
26
+ if selected_menu:
27
+ st.write(f"μ„ νƒλœ 메뉴: {selected_menu}")
28
+ else:
29
+ st.write("메뉴λ₯Ό μ„ νƒν•΄μ£Όμ„Έμš”.")