import streamlit as st #1.12.2
st.title('Data Visualization')# 副标题
st.header("country:"+country))
2.单选框
import streamlit as st
data = pd.read_csv('data/data.csv')
st.sidebar.header("请在这里筛选:")
country = st.sidebar.selectbox("选择国家:",
options=sorted(data['location'].unique()),# 单选框内容为location列数据)
3.日期选择
import streamlit as st
# 将字符串日期转为日期格式,并排序
date_sorted =sorted([datetime.datetime.strptime(i,"%Y-%m-%d")for i inset(data['date'])])
date_min = st.sidebar.date_input('选择起始日期:',
date_sorted[0],
min_value=date_sorted[0],
max_value=date_sorted[-1],)
4.设置块区域
import streamlit as st
col1, col2= st.columns([1,1])with col1:# 填写col1区域的代码with col2:# 填写col2区域的代码
5.绘制时间动态折线图进度条
import time
import streamlit as st
chart = st.line_chart(data.iloc[[0],:],width=1200,height=600)
progress_bar = st.sidebar.progress(0)
status_text = st.sidebar.empty()with col2:for i inrange(1,len(data)):if i==1:
st.sidebar.write(country,'日期总天数:',len(data),"天")
new_rows = data.iloc[[i],:]
progress=(int(i/(len(data)-1)*100))
status_text.text("Complete %i%% "% progress)
chart.add_rows(new_rows)
progress_bar.progress(progress)
time.sleep(0.05)
st.sidebar.button("Re-run")
st.stop()