最近开始入行streamlit,用起来不要太爽,终于可以完全基于python从后端的数据处理到前端的可视化展示一条龙搞起来,大大加快了单兵生产力的产出。
streamlit本身是个单app的应用,背后是一个脚本从头到脚跑一遍。
于是出现了很多扩展应用,在streamlit的基础上扩展成多app的应用,今天试用了一下streamlit-multipage,可以做成多page的app,其实也没啥神秘的,本质就是通过pickle把一个页面的数据写成文件,再从另外一个页面加载的方式来实现页面之间的通信。
首先pip install streamlit-multipage安装,然后下载了一个计算BMI的源代码看效果。
from streamlit_multipage import MultiPage
def input_page(st, **state):
st.title("Body Mass Index")
weight_ = state["weight"] if "weight" in state else 0.0
weight = st.number_input("Your weight (Kg): ", value=weight_)
height_ = state["height"] if "height" in state else 0.0
height = st.number_input("Your height (m): ", value=height_)
if height and weight:
MultiPage.save({"weight": weight, "height": height})
def compute_page(st, **state):
st.title("Body Mass Index")
if "weight" not in state or "height" not in state:
st.warning("Enter your data before computing. Go to the Input Page"

最低0.47元/天 解锁文章
1812

被折叠的 条评论
为什么被折叠?



