Lashtw commited on
Commit
ccfddb7
·
verified ·
1 Parent(s): 037e39e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -14,6 +14,7 @@ try:
14
  except ImportError:
15
  st.error("請安裝 'kaleido' 套件以啟用圖像導出功能:\n\n $ pip install kaleido")
16
 
 
17
  def load_data(uploaded_file):
18
  """載入並處理CSV檔案"""
19
  try:
@@ -104,9 +105,9 @@ def apply_font_to_all_text(fig):
104
 
105
 
106
  def save_radar_chart_image(fig):
107
- """使用 kaleido 輸出 png 的記憶體檔案"""
108
- img_bytes = pio.to_image(fig, format="png", engine="kaleido")
109
- return img_bytes
110
 
111
  def main():
112
  st.title('學生成績雷達圖產生器')
@@ -134,14 +135,23 @@ def main():
134
 
135
  st.write("### 批次下載雷達圖")
136
  comparison_rows = st.multiselect("選擇比較對象(可多選,如班平均或區標)", df['姓名'].tolist())
137
-
138
  if comparison_rows:
139
 
 
 
 
 
 
 
 
 
 
140
  st.write("### 選擇要下載的圖片")
141
 
142
  # 初始化選取狀態
143
  if 'selected_images' not in st.session_state:
144
- st.session_state.selected_images = {}
145
 
146
  # 建立圖片核取方塊
147
  image_bytes = {}
@@ -160,11 +170,11 @@ def main():
160
  st.image(image_bytes[student],use_container_width=True)
161
  try:
162
  st.checkbox(f"下載 {student}", key=student, value=st.session_state.selected_images[student])
163
- st.session_state.selected_images[student] = st.session_state[student] # 更新選取狀態
164
  except KeyError:
165
- st.session_state.selected_images[student] = False #如果還沒有這個學生則預設為不選
166
  st.checkbox(f"下載 {student}", key=student, value=st.session_state.selected_images[student])
167
- st.session_state.selected_images[student] = st.session_state[student] # 更新選取狀態
168
 
169
  #全部選取和全部不選
170
  if st.button("全部選取"):
 
14
  except ImportError:
15
  st.error("請安裝 'kaleido' 套件以啟用圖像導出功能:\n\n $ pip install kaleido")
16
 
17
+
18
  def load_data(uploaded_file):
19
  """載入並處理CSV檔案"""
20
  try:
 
105
 
106
 
107
  def save_radar_chart_image(fig):
108
+ """使用 kaleido 輸出 png 的記憶體檔案"""
109
+ img_bytes = pio.to_image(fig, format="png", engine="kaleido")
110
+ return img_bytes
111
 
112
  def main():
113
  st.title('學生成績雷達圖產生器')
 
135
 
136
  st.write("### 批次下載雷達圖")
137
  comparison_rows = st.multiselect("選擇比較對象(可多選,如班平均或區標)", df['姓名'].tolist())
138
+
139
  if comparison_rows:
140
 
141
+ st.markdown("""
142
+ <style>
143
+ div[data-baseweb="checkbox"] div {
144
+ font-family: "Microsoft JhengHei", "Noto Sans CJK", Arial;
145
+ font-size: 16px;
146
+ }
147
+ </style>
148
+ """, unsafe_allow_html=True)
149
+
150
  st.write("### 選擇要下載的圖片")
151
 
152
  # 初始化選取狀態
153
  if 'selected_images' not in st.session_state:
154
+ st.session_state.selected_images = {student:False for student in df['姓名'] if student not in comparison_rows}
155
 
156
  # 建立圖片核取方塊
157
  image_bytes = {}
 
170
  st.image(image_bytes[student],use_container_width=True)
171
  try:
172
  st.checkbox(f"下載 {student}", key=student, value=st.session_state.selected_images[student])
173
+ st.session_state.selected_images[student] = st.session_state[student] # 更新選取狀態
174
  except KeyError:
175
+ st.session_state.selected_images[student] = False # 如果還沒有這個學生則預設為不選
176
  st.checkbox(f"下載 {student}", key=student, value=st.session_state.selected_images[student])
177
+ st.session_state.selected_images[student] = st.session_state[student] # 更新選取狀態
178
 
179
  #全部選取和全部不選
180
  if st.button("全部選取"):