安装库:
pip install streamlit
官方api文档:docs.streamlit.io/library/api…
运行方式:
streamlit run run.py
运行后会自动生成 http://localhost:8501/ 网页,若端口被占用,则会使用另外的端口
- 导入库
import streamlit as st - 在网页生成 hello world
st.write("hello world")
- 可以直接在py文件中把想要在网页展示的数据放入代码行中, 无须使用st.write()等显示键入命令
- 支持: MarkDown, 数据, 图表等
- 例子:
# markdown
md = '# 标题'
md
# 数据
x = 10
'x', x
# 图表
import matplotlib.pyplot as plt
import numpy as np
arr = np.random.normal(1, 1, size=10)
fig, ax = plt.subplots()
ax.hist(arr, bins=2)
fig
页面显示:
未完待续