Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -46,8 +46,8 @@ st.markdown('<p class="big-font">ESG 數據視覺化</p>', unsafe_allow_html=Tru
|
|
46 |
st.sidebar.header("設置")
|
47 |
selected_option = st.sidebar.selectbox("選擇資料類型", options=list(urls.keys()))
|
48 |
|
49 |
-
# Button to load data
|
50 |
-
if st.sidebar.button("
|
51 |
with st.spinner('資料載入中...'):
|
52 |
# Add a progress bar
|
53 |
progress_bar = st.progress(0)
|
@@ -65,35 +65,34 @@ if st.sidebar.button("載入資料"):
|
|
65 |
st.subheader("資料摘要")
|
66 |
st.write(df.describe())
|
67 |
|
68 |
-
#
|
69 |
numeric_columns = df.select_dtypes(include=['int64', 'float64']).columns
|
70 |
if len(numeric_columns) > 1:
|
71 |
-
x_column =
|
72 |
-
y_column =
|
73 |
|
74 |
-
#
|
75 |
-
|
76 |
|
77 |
-
#
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
st.plotly_chart(fig, use_container_width=True)
|
97 |
else:
|
98 |
st.warning("沒有足夠的數值型欄位來創建圖表。請選擇另一個數據集。")
|
99 |
|
@@ -106,7 +105,7 @@ if st.sidebar.button("載入資料"):
|
|
106 |
mime="text/csv",
|
107 |
)
|
108 |
else:
|
109 |
-
st.info("
|
110 |
|
111 |
# Footer
|
112 |
st.markdown("---")
|
|
|
46 |
st.sidebar.header("設置")
|
47 |
selected_option = st.sidebar.selectbox("選擇資料類型", options=list(urls.keys()))
|
48 |
|
49 |
+
# Button to load data and analyze
|
50 |
+
if st.sidebar.button("載入並分析數據"):
|
51 |
with st.spinner('資料載入中...'):
|
52 |
# Add a progress bar
|
53 |
progress_bar = st.progress(0)
|
|
|
65 |
st.subheader("資料摘要")
|
66 |
st.write(df.describe())
|
67 |
|
68 |
+
# Automatically select columns for visualization
|
69 |
numeric_columns = df.select_dtypes(include=['int64', 'float64']).columns
|
70 |
if len(numeric_columns) > 1:
|
71 |
+
x_column = df.columns[0] # First column as x-axis
|
72 |
+
y_column = numeric_columns[0] # First numeric column as y-axis
|
73 |
|
74 |
+
# Visualization
|
75 |
+
st.subheader("資料視覺化")
|
76 |
|
77 |
+
# Pie Chart
|
78 |
+
fig_pie = px.pie(df, names=x_column, values=y_column, title=f"{selected_option} 分佈 (圓餅圖)")
|
79 |
+
fig_pie.update_layout(
|
80 |
+
font_family="Taipei Sans TC Beta",
|
81 |
+
title_font_size=24,
|
82 |
+
legend_title_font_size=14,
|
83 |
+
legend_font_size=12
|
84 |
+
)
|
85 |
+
st.plotly_chart(fig_pie, use_container_width=True)
|
86 |
+
|
87 |
+
# Bar Chart
|
88 |
+
fig_bar = px.bar(df, x=x_column, y=y_column, title=f"{selected_option} 比較 (柱狀圖)")
|
89 |
+
fig_bar.update_layout(
|
90 |
+
font_family="Taipei Sans TC Beta",
|
91 |
+
title_font_size=24,
|
92 |
+
legend_title_font_size=14,
|
93 |
+
legend_font_size=12
|
94 |
+
)
|
95 |
+
st.plotly_chart(fig_bar, use_container_width=True)
|
|
|
96 |
else:
|
97 |
st.warning("沒有足夠的數值型欄位來創建圖表。請選擇另一個數據集。")
|
98 |
|
|
|
105 |
mime="text/csv",
|
106 |
)
|
107 |
else:
|
108 |
+
st.info("請在左側選單選擇資料類型,然後點擊「載入並分析數據」按鈕來查看數據和圖表。")
|
109 |
|
110 |
# Footer
|
111 |
st.markdown("---")
|