Roberta2024 commited on
Commit
c510b88
·
verified ·
1 Parent(s): 89bee7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -57,13 +57,18 @@ if st.button("載入資料"):
57
  st.header(f"{selected_option} 資料")
58
  st.dataframe(df)
59
 
60
- # Plotting the data
61
- if selected_option == "溫室氣體":
62
- fig = px.pie(df, names=df.columns[0], values=df.columns[1], title=f"Pie Chart for {selected_option}")
63
- elif selected_option == "再生能源":
64
- fig = px.bar(df, x=df.columns[0], y=df.columns[1], title=f"Bar Chart for {selected_option}")
65
- elif selected_option == "董事會":
66
- fig = px.bar(df, x=df.columns[0], y=df.columns[1], title=f"Bar Chart for {selected_option}")
 
 
 
 
 
67
 
68
  # Apply custom font to the plot
69
  fig.update_layout(font_family="Taipei Sans TC Beta")
 
57
  st.header(f"{selected_option} 資料")
58
  st.dataframe(df)
59
 
60
+ # Column selection for visualization
61
+ x_col = st.selectbox("選擇類別欄位 (X 軸)", options=df.columns)
62
+ y_col = st.selectbox("選擇數值欄位 (Y 軸)", options=df.columns)
63
+
64
+ # Chart type selection
65
+ chart_type = st.radio("選擇圖表類型", ("圓餅圖", "柱狀圖"))
66
+
67
+ # Plotting the data based on user selection
68
+ if chart_type == "圓餅圖":
69
+ fig = px.pie(df, names=x_col, values=y_col, title=f"Pie Chart for {selected_option}")
70
+ elif chart_type == "柱狀圖":
71
+ fig = px.bar(df, x=x_col, y=y_col, title=f"Bar Chart for {selected_option}")
72
 
73
  # Apply custom font to the plot
74
  fig.update_layout(font_family="Taipei Sans TC Beta")