Roberta2024 commited on
Commit
3e2408a
·
verified ·
1 Parent(s): d99ac8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -28
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
- # Column selection for visualization
69
  numeric_columns = df.select_dtypes(include=['int64', 'float64']).columns
70
  if len(numeric_columns) > 1:
71
- x_column = st.selectbox("選擇 X 軸欄位", options=df.columns)
72
- y_column = st.selectbox("選擇 Y 軸欄位", options=numeric_columns)
73
 
74
- # Chart type selection
75
- chart_type = st.radio("選擇圖表類型", ("圓餅圖", "柱狀圖"))
76
 
77
- # Button to trigger analysis
78
- if st.button("分析數據"):
79
- # Visualization
80
- st.subheader("資料視覺化")
81
-
82
- if chart_type == "圓餅圖":
83
- fig = px.pie(df, names=x_column, values=y_column, title=f"{selected_option} 分佈")
84
- else: # 柱狀圖
85
- fig = px.bar(df, x=x_column, y=y_column, title=f"{selected_option} 比較")
86
-
87
- # Apply custom font and styling to the plot
88
- fig.update_layout(
89
- font_family="Taipei Sans TC Beta",
90
- title_font_size=24,
91
- legend_title_font_size=14,
92
- legend_font_size=12
93
- )
94
-
95
- # Display the chart
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("---")