streamlit 数据简易可视化的web库

看到同事一网页, F12 看了一下,发现了这个
果然是非常简单。

基础

使用Streamlit快速搭建数据科学Web App
Streamlit API 介绍

安装:pip install streamlit
运行:

  • 示例代码: streamlit hello
  • 自己的: streamlit run 1.test.py --server.port 80
  • 好像也可以执行网上的

特点:支持修改的代码自动刷新非常方便
原理:就是动态执行脚本,从上到下,不过应该有缓存不至于慢

配置,建议一开始不要加,
~/.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)

效果
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值