看到同事一网页, F12 看了一下,发现了这个
果然是非常简单。
使用Streamlit快速搭建数据科学Web App
Streamlit API 介绍
安装:pip install streamlit
运行:
特点:支持修改的代码自动刷新非常方便
原理:就是动态执行脚本,从上到下,不过应该有缓存不至于慢
配置,建议一开始不要加,
~/.streamlit/config.toml
[runner]
magicEnabled = false
[browser]
gatherUsageStats = false
防止提示plt 的问题
st.set_option('deprecation.showPyplotGlobalUse', False)
分页例子
import streamlit as st
sunset_imgs = [
'https://unsplash.com/photos/-IMlv9Jlb24/download?force=true',
'https://unsplash.com/photos/ESEnXckWlLY/download?force=true',
'https://unsplash.com/photos/mOcdke2ZQoE/download?force=true',
'https://unsplash.com/photos/GPPAjJicemU/download?force=true',
'https://unsplash.com/photos/JFeOy62yjXk/download?force=true',
'https://unsplash.com/photos/kEgJVDkQkbU/download?force=true',
'https://unsplash.com/photos/i9Q9bc-WgfE/download?force=true',
'https://unsplash.com/photos/tIL1v1jSoaY/download?force=true',
'https://unsplash.com/photos/-G3rw6Y02D0/download?force=true',
'https://unsplash.com/photos/xP_AGmeEa6s/download?force=true',
'https://unsplash.com/photos/4iTVoGYY7bM/download?force=true',
'https://unsplash.com/photos/mBQIfKlvowM/download?force=true',
'https://unsplash.com/photos/A-11N8ItHZo/download?force=true',
'https://unsplash.com/photos/kOqBCFsGTs8/download?force=true',
'https://unsplash.com/photos/8DMuvdp-vso/download?force=true'
]
N = 6
page_number = 0
last_page = len(sunset_imgs) // N
prev, _ ,next = st.beta_columns([1, 10, 1]) # 布局
if next.button("Next"):
if page_number + 1 > last_page:
page_number = 0
else:
page_number += 1
if prev.button("Previous"):
if page_number - 1 < 0:
page_number = last_page
else:
page_number -= 1
start_idx = page_number * N
end_idx = (1 + page_number) * N
fimgs=sunset_imgs[start_idx:end_idx]
st.image(fimgs, width=100)