m1, m2, m3, m4, m5 = st.columns((1,1,1,1,1))
todf = pd.read_excel('DataforMock.xlsx',sheet_name = 'metrics')
to = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Total Outstanding')]
ch = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Current Handover Average Mins')]
hl = todf[(todf['Hospital Attended']==hosp) & (todf['Metric']== 'Hours Lost to Handovers Over 15 Mins')]
m1.write('')
m2.metric(label ='Total Outstanding Handovers',value = int(to['Value']), delta = str(int(to['Previous']))+' Compared to 1 hour ago', delta_color = 'inverse')
m3.metric(label ='Current Handover Average',value = str(int(ch['Value']))+" Mins", delta = str(int(ch['Previous']))+' Compared to 1 hour ago', delta_color = 'inverse')
m4.metric(label = 'Time Lost today (Above 15 mins)',value = str(int(hl['Value']))+" Hours", delta = str(int(hl['Previous']))+' Compared to yesterday')
m1.write('')
# Number of Completed Handovers by Hour
g1, g2, g3 = st.columns((1,1,1))
fgdf = pd.read_excel('DataforMock.xlsx',sheet_name = 'Graph')
fgdf = fgdf[fgdf['Hospital Attended']==hosp]
fig = px.bar(fgdf, x = 'Arrived Destination Resolved', y='Number of Handovers', template = 'seaborn')
fig.update_traces(marker_color='#264653')
fig.update_layout(title_text="Number of Completed Handovers by Hour",title_x=0,margin= dict(l=0,r=10,b=10,t=30), yaxis_title=None, xaxis_title=None)
g1.plotly_chart(fig, use_container_width=True)
这段代码实现了第1个图的展示,根据selectbox的选择会有变化,非常典型的自上而下的streamlit写法。
而SimpleStart是基于事件响应的,就是说selectbox选择时,需要执行一个事件函数完成这些代码。
改编后代码是这样的
def calc2(state = None, value = None):
hosp = select1.value
# Number of Completed Handovers by Hour
fgdf = pd.read_excel('DataforMock.xlsx',sheet_name = 'Graph')
fgdf = fgdf[fgdf['Hospital Attended']==hosp]
fig = px.bar(fgdf, x = 'Arrived Destination Resolved', y='Number of Handovers', template = 'seaborn')
fig.update_traces(marker_color='#264653')
fig.update_layout(title_text="Number of Completed Handovers by Hour",title_x=0,margin= dict(l=0,r=10,b=10,t=30), yaxis_title=None, xaxis_title=None)
plotly_chart1.update(fig)
hosp_df = pd.read_excel(‘DataforMock.xlsx’,sheet_name = ‘Hospitals’)
select1 = ss.selectbox(hosp_df, label = ‘Choose Hospital’, help = ‘Filter report to show only one hospital’, οnchange=calc)
hosp = “All”
m1, m2, m3, m4, m5 = ss.columns((1,1,1,1,1), design=False)
todf = pd.read_excel(‘DataforMock.xlsx’,sheet_name = ‘metrics’)
m1.write(‘’)
metric1 = m2.metric(label = “demo”, value = 0, delta = 0)
metric2 = m3.metric()#也可以什么参数都不写,先占位,以后在事件函数里 用metric2.update更新数据
metric3 = m4.metric()
g1, g2, g3 = ss.columns((1,1,1), design = False)
plotly_chart1 = g1.plotly_chart()
plotly_chart2 = g2.plotly_chart()
plotly_chart3 = g3.plotly_chart()
calc2()
就是原来的g1.plotly\_chart(fig, use\_container\_width=True) , 先用 plotly\_chart1 = g1.plotly\_chart() 占位,后面的数据部分移到了事件响应函数calc2里。其它代码逻辑几乎都一样。
##### 在线演示和代码
[SimpleStart-西南医院救护车可视化数据-在线演示]( )
[项目源代码]( )
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数Python工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年Python开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
![img](https://img-blog.csdnimg.cn/img_convert/456ae908fc8c5756e09197c5de7f2eed.png)
![img](https://img-blog.csdnimg.cn/img_convert/32ddc236780e4ce067707b783f94a2fd.png)
![img](https://img-blog.csdnimg.cn/img_convert/987414188a8ea28910c59b3f49a1a363.png)
![img](https://img-blog.csdnimg.cn/img_convert/5dfbe3e1f71eeac3e0e1a82dac6f4ea3.png)
![img](https://img-blog.csdnimg.cn/img_convert/6c361282296f86381401c05e862fe4e9.png)
![img](https://img-blog.csdnimg.cn/img_convert/9f49b566129f47b8a67243c1008edf79.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!**
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
**如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)**
于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
**如果你觉得这些内容对你有帮助,可以扫码获取!!!(备注:Python)**
![](https://img-blog.csdnimg.cn/img_convert/b60c29245824ca91193601f960df950b.jpeg)