Sanstyle 家族¶
为了方便管理代码和数据创建仓库:
xinetzone/dash-xinet:简化 Dash 的使用。
SanstyleLab/plotly-dastsets:存储一些数据集以及展示图片。
xinetzone/sanstyle:处理一些常见任务。
安装:
pip install dash-xinet sanstyle -i https://pypi.org/simple/
dash_xinet
¶
from dash_xinet.server import create_app, run_server
from dash_xinet.utils.nav import create_nav
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = create_app(__name__, external_stylesheets=external_stylesheets)
Dash 应用使用和运行:
layout = ... # 布局
await run_server(app, layout, port=8050) # 启动应用
sanstyle
¶
可以直接批量修改文件后缀:
rename_suffix(root, old, new)
root
需要修改的跟目录
old
被修改的文件后缀,如
.txt
new
修改后的文件后缀,如
.rst
创建 <embed>
元素¶
from sanstyle.display.html import Embed
snippet_url = 'https://dash-book.herokuapp.com'
figure_n_slider_dash = Embed(snippet_url + '/examples/figure-n-slider',
className='w3-pale-blue',
height=500)
figure_n_slider_dash
导入 plotly-dastsets
¶
import pandas as pd
from sanstyle.github.file import lfs_url
url = lfs_url('SanstyleLab/plotly-dastsets',
'simple/usa-agricultural-exports-2011.csv')
df = pd.read_csv(url)
df.head()
Unnamed: 0 | state | total exports | beef | pork | poultry | dairy | fruits fresh | fruits proc | total fruits | veggies fresh | veggies proc | total veggies | corn | wheat | cotton | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | Alabama | 1390.63 | 34.4 | 10.6 | 481.0 | 4.06 | 8.0 | 17.1 | 25.11 | 5.5 | 8.9 | 14.33 | 34.9 | 70.0 | 317.61 |
1 | 1 | Alaska | 13.31 | 0.2 | 0.1 | 0.0 | 0.19 | 0.0 | 0.0 | 0.00 | 0.6 | 1.0 | 1.56 | 0.0 | 0.0 | 0.00 |
2 | 2 | Arizona | 1463.17 | 71.3 | 17.9 | 0.0 | 105.48 | 19.3 | 41.0 | 60.27 | 147.5 | 239.4 | 386.91 | 7.3 | 48.7 | 423.95 |
3 | 3 | Arkansas | 3586.02 | 53.2 | 29.4 | 562.9 | 3.53 | 2.2 | 4.7 | 6.88 | 4.4 | 7.1 | 11.45 | 69.5 | 114.5 | 665.44 |
4 | 4 | California | 16472.88 | 228.7 | 11.1 | 225.4 | 929.95 | 2791.8 | 5944.6 | 8736.40 | 803.2 | 1303.5 | 2106.79 | 34.6 | 249.3 | 1064.95 |