Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -99,95 +99,35 @@ def get_ncku_data():
|
|
99 |
# 主程序
|
100 |
st.title("醫院病床狀況")
|
101 |
|
102 |
-
#
|
103 |
-
|
104 |
"選擇要查看的醫院",
|
105 |
-
|
|
|
106 |
)
|
107 |
|
108 |
# 查詢按鈕
|
109 |
if st.button("查詢"):
|
110 |
-
|
111 |
-
df = get_tmh_data()
|
112 |
-
st.write(df)
|
113 |
-
|
114 |
-
# 美化病床類別分布直條圖
|
115 |
-
fig_bar = px.bar(df, x='病床類別', y='病床數', title='台南市立醫院病床類別分布',
|
116 |
-
color='病床類別', text='病床數',
|
117 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
118 |
-
fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
119 |
-
fig_bar.update_layout(uniformtext_minsize=8, uniformtext_mode='hide',
|
120 |
-
xaxis_title='病床類別', yaxis_title='病床數',
|
121 |
-
title_x=0.5, template='plotly_white')
|
122 |
-
st.plotly_chart(fig_bar)
|
123 |
-
|
124 |
-
# 病床類別分布圓餅圖
|
125 |
-
fig_pie_beds = px.pie(df, names='病床類別', values='病床數', title='台南市立醫院病床類別分布',
|
126 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
127 |
-
st.plotly_chart(fig_pie_beds)
|
128 |
-
|
129 |
-
# 空床數分布圓餅圖
|
130 |
-
fig_pie_empty = px.pie(df, names='病床類別', values='空床數', title='台南市立醫院空床數分布',
|
131 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
132 |
-
st.plotly_chart(fig_pie_empty)
|
133 |
-
|
134 |
-
elif option == "奇美醫院":
|
135 |
-
df = get_chimei_data()
|
136 |
-
st.write(df)
|
137 |
-
|
138 |
-
# 美化病床類別分布直條圖
|
139 |
-
fig_bar = px.bar(df, x='病床類別', y='病床數', title='奇美醫院病床類別分布',
|
140 |
-
color='病床類別', text='病床數',
|
141 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
142 |
-
fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
143 |
-
fig_bar.update_layout(uniformtext_minsize=8, uniformtext_mode='hide',
|
144 |
-
xaxis_title='病床類別', yaxis_title='病床數',
|
145 |
-
title_x=0.5, template='plotly_white')
|
146 |
-
st.plotly_chart(fig_bar)
|
147 |
-
|
148 |
-
# 病床類別分布圓餅圖
|
149 |
-
fig_pie_beds = px.pie(df, names='病床類別', values='病床數', title='奇美醫院病床類別分布',
|
150 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
151 |
-
st.plotly_chart(fig_pie_beds)
|
152 |
-
|
153 |
-
# 空床數分布圓餅圖
|
154 |
-
fig_pie_empty = px.pie(df, names='病床類別', values='空床數', title='奇美醫院空床數分布',
|
155 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
156 |
-
st.plotly_chart(fig_pie_empty)
|
157 |
|
158 |
-
|
159 |
-
df = get_ncku_data()
|
160 |
-
st.write(df)
|
161 |
-
|
162 |
-
# 美化病床類別分布直條圖
|
163 |
-
fig_bar = px.bar(df, x='病床類別', y='病床數', title='成大醫院病床類別分布',
|
164 |
-
color='病床類別', text='病床數',
|
165 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
166 |
-
fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
167 |
-
fig_bar.update_layout(uniformtext_minsize=8, uniformtext_mode='hide',
|
168 |
-
xaxis_title='病床類別', yaxis_title='病床數',
|
169 |
-
title_x=0.5, template='plotly_white')
|
170 |
-
st.plotly_chart(fig_bar)
|
171 |
-
|
172 |
-
# 病床類別分布圓餅圖
|
173 |
-
fig_pie_beds = px.pie(df, names='病床類別', values='病床數', title='成大醫院病床類別分布',
|
174 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
175 |
-
st.plotly_chart(fig_pie_beds)
|
176 |
-
|
177 |
-
# 空床數分布圓餅圖
|
178 |
-
fig_pie_empty = px.pie(df, names='病床類別', values='空床數', title='成大醫院空床數分布',
|
179 |
-
color_discrete_sequence=px.colors.qualitative.Pastel)
|
180 |
-
st.plotly_chart(fig_pie_empty)
|
181 |
-
|
182 |
-
elif option == "三間醫院統整":
|
183 |
df_tmh = get_tmh_data()
|
|
|
|
|
|
|
184 |
df_chimei = get_chimei_data()
|
|
|
|
|
|
|
185 |
df_ncku = get_ncku_data()
|
186 |
-
|
|
|
|
|
|
|
187 |
st.write(df_combined)
|
188 |
|
189 |
# 美化病床類別��布直條圖
|
190 |
-
fig_bar = px.bar(df_combined, x='病床類別', y='病床數', color='醫院', title='
|
191 |
text='病床數', barmode='group',
|
192 |
color_discrete_sequence=px.colors.qualitative.Pastel)
|
193 |
fig_bar.update_traces(texttemplate='%{text:.2s}', textposition='outside')
|
@@ -197,11 +137,11 @@ if st.button("查詢"):
|
|
197 |
st.plotly_chart(fig_bar)
|
198 |
|
199 |
# 病床類別分布圓餅圖
|
200 |
-
fig_pie_beds = px.pie(df_combined, names='病床類別', values='病床數', title='
|
201 |
color_discrete_sequence=px.colors.qualitative.Pastel)
|
202 |
st.plotly_chart(fig_pie_beds)
|
203 |
|
204 |
# 空床數分布圓餅圖
|
205 |
-
fig_pie_empty = px.pie(df_combined, names='病床類別', values='空床數', title='
|
206 |
color_discrete_sequence=px.colors.qualitative.Pastel)
|
207 |
-
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 |
+
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')
|
|
|
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)
|