Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,7 +50,7 @@ def create_radar_chart(df, selected_rows, selected_columns):
|
|
| 50 |
dash=line_styles[i % len(line_styles)],
|
| 51 |
width=2
|
| 52 |
),
|
| 53 |
-
marker=dict(opacity=0.5)
|
| 54 |
))
|
| 55 |
|
| 56 |
fig.update_layout(
|
|
@@ -58,15 +58,15 @@ def create_radar_chart(df, selected_rows, selected_columns):
|
|
| 58 |
radialaxis=dict(
|
| 59 |
visible=True,
|
| 60 |
range=[0, df[selected_columns].values.max() * 1.1],
|
| 61 |
-
tickfont=dict(size=12, color='black') #
|
| 62 |
),
|
| 63 |
angularaxis=dict(
|
| 64 |
-
tickfont=dict(size=16, color='black') #
|
| 65 |
)
|
| 66 |
),
|
| 67 |
showlegend=True,
|
| 68 |
legend=dict(
|
| 69 |
-
font=dict(size=14, color='black') #
|
| 70 |
),
|
| 71 |
title='學生成績雷達圖',
|
| 72 |
plot_bgcolor='white', # 背景為白色
|
|
@@ -85,10 +85,10 @@ def save_all_radar_charts(df, selected_columns, comparison_rows):
|
|
| 85 |
for student in df['姓名']:
|
| 86 |
if student in comparison_rows:
|
| 87 |
continue
|
| 88 |
-
|
| 89 |
fig = create_radar_chart(df, [student] + comparison_rows, selected_columns)
|
| 90 |
|
| 91 |
-
#
|
| 92 |
fig.update_layout(
|
| 93 |
font=dict(
|
| 94 |
family="Microsoft JhengHei, Noto Sans CJK, Arial"
|
|
@@ -96,7 +96,8 @@ def save_all_radar_charts(df, selected_columns, comparison_rows):
|
|
| 96 |
)
|
| 97 |
|
| 98 |
file_path = os.path.join(output_dir, f"{student}_comparison.png")
|
| 99 |
-
fig.write_image(file_path, engine="kaleido"
|
|
|
|
| 100 |
|
| 101 |
# 壓縮所有圖表
|
| 102 |
zip_path = "radar_charts.zip"
|
|
@@ -140,13 +141,22 @@ def main():
|
|
| 140 |
else:
|
| 141 |
zip_path = save_all_radar_charts(df, selected_columns, comparison_rows)
|
| 142 |
with open(zip_path, "rb") as f:
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
|
|
|
|
|
|
| 149 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 152 |
main()
|
|
|
|
| 50 |
dash=line_styles[i % len(line_styles)],
|
| 51 |
width=2
|
| 52 |
),
|
| 53 |
+
marker=dict(opacity=0.5)
|
| 54 |
))
|
| 55 |
|
| 56 |
fig.update_layout(
|
|
|
|
| 58 |
radialaxis=dict(
|
| 59 |
visible=True,
|
| 60 |
range=[0, df[selected_columns].values.max() * 1.1],
|
| 61 |
+
tickfont=dict(size=12, color='black', family="Microsoft JhengHei, Noto Sans CJK, Arial") # 調整刻度文字顏色為黑色並設定字體
|
| 62 |
),
|
| 63 |
angularaxis=dict(
|
| 64 |
+
tickfont=dict(size=16, color='black', family="Microsoft JhengHei, Noto Sans CJK, Arial") # 放大字體,顏色為黑色並設定字體
|
| 65 |
)
|
| 66 |
),
|
| 67 |
showlegend=True,
|
| 68 |
legend=dict(
|
| 69 |
+
font=dict(size=14, color='black', family="Microsoft JhengHei, Noto Sans CJK, Arial") # 圖例文字加大並改為黑色並設定字體
|
| 70 |
),
|
| 71 |
title='學生成績雷達圖',
|
| 72 |
plot_bgcolor='white', # 背景為白色
|
|
|
|
| 85 |
for student in df['姓名']:
|
| 86 |
if student in comparison_rows:
|
| 87 |
continue
|
| 88 |
+
|
| 89 |
fig = create_radar_chart(df, [student] + comparison_rows, selected_columns)
|
| 90 |
|
| 91 |
+
# 在這裡更新字型,確保字型有被設定
|
| 92 |
fig.update_layout(
|
| 93 |
font=dict(
|
| 94 |
family="Microsoft JhengHei, Noto Sans CJK, Arial"
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
file_path = os.path.join(output_dir, f"{student}_comparison.png")
|
| 99 |
+
fig.write_image(file_path, engine="kaleido",
|
| 100 |
+
font_family="Microsoft JhengHei, Noto Sans CJK, Arial") # 在这里加入字型设定
|
| 101 |
|
| 102 |
# 壓縮所有圖表
|
| 103 |
zip_path = "radar_charts.zip"
|
|
|
|
| 141 |
else:
|
| 142 |
zip_path = save_all_radar_charts(df, selected_columns, comparison_rows)
|
| 143 |
with open(zip_path, "rb") as f:
|
| 144 |
+
st.download_button(
|
| 145 |
+
label="下載壓縮檔",
|
| 146 |
+
data=f,
|
| 147 |
+
file_name="radar_charts.zip",
|
| 148 |
+
mime="application/zip",
|
| 149 |
+
key="download_button",
|
| 150 |
+
on_click=lambda: st.session_state.update({'download_triggered':True}), # 设置下载触发标记
|
| 151 |
+
disabled=st.session_state.get("download_triggered",False) # 如果已下载则禁用下载按钮
|
| 152 |
)
|
| 153 |
+
|
| 154 |
+
st.session_state.download_triggered = False
|
| 155 |
+
|
| 156 |
+
|
| 157 |
|
| 158 |
if __name__ == "__main__":
|
| 159 |
+
if 'download_triggered' not in st.session_state:
|
| 160 |
+
st.session_state.download_triggered = False
|
| 161 |
+
|
| 162 |
main()
|