Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
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)
|