Roberta2024 commited on
Commit
6e9fe05
·
verified ·
1 Parent(s): 9a409f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -36,9 +36,14 @@ def fetch_data(hospital_url, table_id, hospital_name):
36
 
37
  return pd.DataFrame(data, columns=columns)
38
 
39
- # 定義繪圖函數
40
- def plot_data(df):
41
- fig = px.bar(df, x='病床種類', y='床位別數', color='醫院', barmode='group', title="各醫院床位分配情況")
 
 
 
 
 
42
  st.plotly_chart(fig)
43
 
44
  # Streamlit UI
@@ -97,7 +102,8 @@ if st.button("爬取資料"):
97
 
98
  # 添加繪製按鈕
99
  if st.button("繪製圖表"):
100
- plot_data(all_data)
 
101
 
102
  else:
103
  st.error("沒有成功爬取任何數據。")
 
36
 
37
  return pd.DataFrame(data, columns=columns)
38
 
39
+ # 定義繪製圓餅圖的函數
40
+ def plot_pie_chart(df):
41
+ fig = px.pie(df, names='病床種類', values='床位別數', title='各類病床床位佔比')
42
+ st.plotly_chart(fig)
43
+
44
+ # 定義繪製柱狀圖的函數
45
+ def plot_bar_chart(df):
46
+ fig = px.bar(df, x='病床種類', y='床位別數', color='醫院', barmode='group', title="各醫院病床分佈")
47
  st.plotly_chart(fig)
48
 
49
  # Streamlit UI
 
102
 
103
  # 添加繪製按鈕
104
  if st.button("繪製圖表"):
105
+ plot_pie_chart(all_data)
106
+ plot_bar_chart(all_data)
107
 
108
  else:
109
  st.error("沒有成功爬取任何數據。")