Dash Xinet 与 Sanstyle#

为了方便管理代码和数据创建仓库:

安装:

pip install dash-xinet sanstyle

统一载入模块和库(后文将省略这部分代码):

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#

可以直接批量修改文件后缀:

from sanstyle.utils import rename_suffix
rename_suffix(root, old, new)

root : 需要修改的跟目录

old : 被修改的文件后缀,如 .txt

new : 修改后的文件后缀,如 .rst

创建 <embed> 元素#

from sanstyle.display.html import Embed

snippet_url = 'https://dash-tests.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()
/tmp/ipykernel_2184/2379929884.py:1: DeprecationWarning: 
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466
        
  import pandas as pd
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

更多关于 dash_xinetsanstyle 的信息可阅读:Sanstyle 家族