dltmdgus commited on
Commit
d4a09ac
Β·
verified Β·
1 Parent(s): 8c65269

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -6,7 +6,6 @@ import seaborn as sns
6
  import matplotlib.font_manager as fm
7
  from matplotlib import rc
8
 
9
-
10
  # μ‚¬μ΄λ“œλ°”μ— λͺ©μ°¨ μΆ”κ°€
11
  st.sidebar.title("λͺ©μ°¨")
12
  page = st.sidebar.radio("νŽ˜μ΄μ§€ 선택", ["μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ", "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄"])
@@ -19,6 +18,16 @@ def load_data(file_path):
19
  st.error(f"데이터λ₯Ό λ‘œλ“œν•˜λŠ” λ™μ•ˆ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")
20
  return pd.DataFrame()
21
 
 
 
 
 
 
 
 
 
 
 
22
  if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
23
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ")
24
 
@@ -50,7 +59,7 @@ if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
50
 
51
  # λ§‰λŒ€ κ·Έλž˜ν”„ μ‹œκ°ν™”
52
  if not filtered_books.empty:
53
- font_path = 'NanumGothic-Regular.ttf'
54
  st.write(f"μƒμœ„ 5 λ„μ„œ (μ—°λ ΉλŒ€: {selected_age}, 성별: {selected_gender})")
55
  fig, ax = plt.subplots(figsize=(10, 6))
56
  sns.barplot(data=filtered_books, x='λ„μ„œλͺ…', y='λŒ€μΆœκ±΄μˆ˜', palette='viridis', ax=ax)
@@ -65,7 +74,7 @@ if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
65
  elif page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄":
66
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄")
67
 
68
- # 데이터 λ‘œλ“œ
69
  df = load_data(r'μƒμœ„_3_μž₯λ₯΄.xlsx')
70
  if df.empty:
71
  st.stop()
 
6
  import matplotlib.font_manager as fm
7
  from matplotlib import rc
8
 
 
9
  # μ‚¬μ΄λ“œλ°”μ— λͺ©μ°¨ μΆ”κ°€
10
  st.sidebar.title("λͺ©μ°¨")
11
  page = st.sidebar.radio("νŽ˜μ΄μ§€ 선택", ["μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ", "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄"])
 
18
  st.error(f"데이터λ₯Ό λ‘œλ“œν•˜λŠ” λ™μ•ˆ 였λ₯˜κ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€: {e}")
19
  return pd.DataFrame()
20
 
21
+ # 폰트 μ„€μ •
22
+ def set_font():
23
+ font_path = 'NanumGothic-Regular.ttf' # 같은 디렉토리 λ‚΄μ˜ 폰트 파일 경둜
24
+ if not os.path.isfile(font_path):
25
+ st.error(f"폰트 νŒŒμΌμ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€: {font_path}")
26
+ return
27
+
28
+ font_prop = fm.FontProperties(fname=font_path)
29
+ rc('font', family=font_prop.get_name())
30
+
31
  if page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ":
32
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 5개 λŒ€μΆœ λ„μ„œ")
33
 
 
59
 
60
  # λ§‰λŒ€ κ·Έλž˜ν”„ μ‹œκ°ν™”
61
  if not filtered_books.empty:
62
+ set_font()
63
  st.write(f"μƒμœ„ 5 λ„μ„œ (μ—°λ ΉλŒ€: {selected_age}, 성별: {selected_gender})")
64
  fig, ax = plt.subplots(figsize=(10, 6))
65
  sns.barplot(data=filtered_books, x='λ„μ„œλͺ…', y='λŒ€μΆœκ±΄μˆ˜', palette='viridis', ax=ax)
 
74
  elif page == "μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄":
75
  st.title("μ—°λ ΉλŒ€ 및 성별에 λ”°λ₯Έ μƒμœ„ 3개 μž₯λ₯΄")
76
 
77
+ # 데이터 λ‘œλ“œ
78
  df = load_data(r'μƒμœ„_3_μž₯λ₯΄.xlsx')
79
  if df.empty:
80
  st.stop()