Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ def load_data(url):
|
|
29 |
|
30 |
# Streamlit 應用
|
31 |
st.title("2024 台灣企業ESG數據分析與揭露")
|
32 |
-
st.subheader("以溫室氣體X再生能源X董事會資訊")
|
33 |
|
34 |
# 允許用戶選擇數據集
|
35 |
dataset_choice = st.selectbox("選擇要顯示的數據集", list(urls.keys()))
|
@@ -37,6 +37,10 @@ dataset_choice = st.selectbox("選擇要顯示的數據集", list(urls.keys()))
|
|
37 |
# 加載選定的數據集
|
38 |
selected_df = load_data(urls[dataset_choice])
|
39 |
|
|
|
|
|
|
|
|
|
40 |
# 允許用戶選擇用於繪製圖表的列
|
41 |
column_choice = st.selectbox("選擇欄位來繪製圖表", selected_df.columns)
|
42 |
|
@@ -56,14 +60,27 @@ if st.button("生成圖表"):
|
|
56 |
with tab1:
|
57 |
# 使用 plotly 創建圓餅圖
|
58 |
fig_pie = px.pie(selected_df, names=selected_df.index, values=column_choice,
|
59 |
-
title=f"{dataset_choice} - {column_choice} 圓餅圖"
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
with tab2:
|
63 |
# 使用 plotly 創建長條圖
|
64 |
fig_bar = px.bar(selected_df, x=selected_df.index, y=column_choice,
|
65 |
-
title=f"{dataset_choice} - {column_choice} 長條圖"
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
st.success("圖表生成完成!")
|
69 |
else:
|
|
|
29 |
|
30 |
# Streamlit 應用
|
31 |
st.title("2024 台灣企業ESG數據分析與揭露")
|
32 |
+
st.subheader("以溫室氣體 X 再生能源 X 董事會資訊")
|
33 |
|
34 |
# 允許用戶選擇數據集
|
35 |
dataset_choice = st.selectbox("選擇要顯示的數據集", list(urls.keys()))
|
|
|
37 |
# 加載選定的數據集
|
38 |
selected_df = load_data(urls[dataset_choice])
|
39 |
|
40 |
+
# 顯示爬取的資料
|
41 |
+
st.write("### 爬取的資料預覽")
|
42 |
+
st.dataframe(selected_df.head())
|
43 |
+
|
44 |
# 允許用戶選擇用於繪製圖表的列
|
45 |
column_choice = st.selectbox("選擇欄位來繪製圖表", selected_df.columns)
|
46 |
|
|
|
60 |
with tab1:
|
61 |
# 使用 plotly 創建圓餅圖
|
62 |
fig_pie = px.pie(selected_df, names=selected_df.index, values=column_choice,
|
63 |
+
title=f"{dataset_choice} - {column_choice} 圓餅圖",
|
64 |
+
color_discrete_sequence=px.colors.qualitative.Pastel)
|
65 |
+
fig_pie.update_traces(textposition='inside', textinfo='percent+label')
|
66 |
+
fig_pie.update_layout(
|
67 |
+
font=dict(size=14),
|
68 |
+
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1)
|
69 |
+
)
|
70 |
+
st.plotly_chart(fig_pie, use_container_width=True)
|
71 |
|
72 |
with tab2:
|
73 |
# 使用 plotly 創建長條圖
|
74 |
fig_bar = px.bar(selected_df, x=selected_df.index, y=column_choice,
|
75 |
+
title=f"{dataset_choice} - {column_choice} 長條圖",
|
76 |
+
color_discrete_sequence=px.colors.qualitative.Pastel)
|
77 |
+
fig_bar.update_layout(
|
78 |
+
xaxis_title="企業",
|
79 |
+
yaxis_title=column_choice,
|
80 |
+
font=dict(size=14),
|
81 |
+
xaxis_tickangle=-45
|
82 |
+
)
|
83 |
+
st.plotly_chart(fig_bar, use_container_width=True)
|
84 |
|
85 |
st.success("圖表生成完成!")
|
86 |
else:
|