YU-XI commited on
Commit
0cbf01b
·
verified ·
1 Parent(s): fbb0e76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -39
app.py CHANGED
@@ -99,49 +99,52 @@ def get_ncku_data():
99
  # 主程序
100
  st.title("醫院病床狀況")
101
 
102
- # 多項選擇下拉式選單
103
  options = st.multiselect(
104
  "選擇要查看的醫院",
105
  ["台南市立醫院", "奇美醫院", "成大醫院"],
106
- default=["台南市立醫院", "奇美醫院", "成大醫院"]
107
  )
108
 
109
  # 查詢按鈕
110
  if st.button("查詢"):
111
- selected_data = []
112
-
113
- if "台南市立醫院" in options:
114
- df_tmh = get_tmh_data()
115
- selected_data.append(df_tmh)
116
-
117
- if "奇美醫院" in options:
118
- df_chimei = get_chimei_data()
119
- selected_data.append(df_chimei)
120
-
121
- if "成大醫院" in options:
122
- df_ncku = get_ncku_data()
123
- selected_data.append(df_ncku)
124
-
125
- if selected_data:
126
- df_combined = pd.concat(selected_data, ignore_index=True)
127
- st.write(df_combined)
128
-
129
- # 美化病床類別分布直條圖
130
- fig_bar = px.bar(df_combined, x='病床類別', y='病床數', color='醫院', title='病床類別分布',
131
- text='病床數', barmode='group',
132
- color_discrete_sequence=px.colors.qualitative.Pastel)
133
- fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
134
- fig_bar.update_layout(uniformtext_minsize=8, uniformtext_mode='hide',
135
- xaxis_title='病床類別', yaxis_title='病床數',
136
- title_x=0.5, template='plotly_white')
137
- st.plotly_chart(fig_bar)
138
-
139
- # 病床類別分布圓餅圖
140
- fig_pie_beds = px.pie(df_combined, names='病床類別', values='病床數', title='病床類別分布',
141
- color_discrete_sequence=px.colors.qualitative.Pastel)
142
- st.plotly_chart(fig_pie_beds)
143
-
144
- # 空床數分布圓餅圖
145
- fig_pie_empty = px.pie(df_combined, names='病床類別', values='空床數', title='空床數分布',
146
- color_discrete_sequence=px.colors.qualitative.Pastel)
147
- st.plotly_chart(fig_pie_empty)
 
 
 
 
99
  # 主程序
100
  st.title("醫院病床狀況")
101
 
102
+ # 多項選擇下拉式選單,預設選項為"請選擇"
103
  options = st.multiselect(
104
  "選擇要查看的醫院",
105
  ["台南市立醫院", "奇美醫院", "成大醫院"],
106
+ default=[]
107
  )
108
 
109
  # 查詢按鈕
110
  if st.button("查詢"):
111
+ if not options:
112
+ st.warning("請選擇至少一個醫院進行查詢。")
113
+ else:
114
+ selected_data = []
115
+
116
+ if "台南市立醫院" in options:
117
+ df_tmh = get_tmh_data()
118
+ selected_data.append(df_tmh)
119
+
120
+ if "奇美醫院" in options:
121
+ df_chimei = get_chimei_data()
122
+ selected_data.append(df_chimei)
123
+
124
+ if "成大醫院" in options:
125
+ df_ncku = get_ncku_data()
126
+ selected_data.append(df_ncku)
127
+
128
+ if selected_data:
129
+ df_combined = pd.concat(selected_data, ignore_index=True)
130
+ st.write(df_combined)
131
+
132
+ # 美化病床類別分布直條圖
133
+ fig_bar = px.bar(df_combined, x='病床類別', y='病床數', color='醫院', title='病床類別分布',
134
+ text='病床數', barmode='group',
135
+ color_discrete_sequence=px.colors.qualitative.Pastel)
136
+ fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
137
+ fig_bar.update_layout(uniformtext_minsize=8, uniformtext_mode='hide',
138
+ xaxis_title='病床類別', yaxis_title='病床數',
139
+ title_x=0.5, template='plotly_white')
140
+ st.plotly_chart(fig_bar)
141
+
142
+ # 病床類別分布圓餅圖
143
+ fig_pie_beds = px.pie(df_combined, names='病床類別', values='病床數', title='病床類別分布',
144
+ color_discrete_sequence=px.colors.qualitative.Pastel)
145
+ st.plotly_chart(fig_pie_beds)
146
+
147
+ # 空床數分布圓餅圖
148
+ fig_pie_empty = px.pie(df_combined, names='病床類別', values='空床數', title='空床數分布',
149
+ color_discrete_sequence=px.colors.qualitative.Pastel)
150
+ st.plotly_chart(fig_pie_empty)