打印短划线自定义组件。将plotly.extendTraces()支持添加到Dash_core_components.graph()
dash-extendable-graph的Python项目详细描述
虚线可扩展图
破折号可扩展图是一个破折号组件库此库包含单个组件:ExtendableGraph
组件是dash-core-components(v 1.1.1)的graph()组件的分支。但是,此组件的extendData
已被修改为遵循与figure['data']
格式匹配的api(与定义的api Graph.extendData
和Plotly.extendTraces()
相反)。
注意:plotly.js是必需的。但是,库并没有显式地列在MANIFEST.in
或dash_extendable_graph\__init__.py
中,以减少束大小。plotly.js已经与Dash核心组件包一起发布,大多数项目将导入DCC和Dash可扩展图。
安装
开始使用:
- 安装破折号和依赖项:https://dash.plot.ly/installation
$ pip install -r requirements.txt
- 安装仪表板可扩展图
$ pip install dash-extendable-graph
- 运行
python usage.py
- 访问网页浏览器中的http://localhost:8050
用法
一般示例可以在usage.py
扩展数据属性
updateData
[list]:一个字典列表,每个字典都包含表示跟踪数据(例如dict(x=[1], y=[1])
)traceIndices
[列表,可选]:标识应扩展的跟踪。如果不存在指定的跟踪索引,则相应的跟踪将附加到该图中。
基于^{updateData
键已被修改以更好地匹配Plotly.plot()
的内容(例如Graph.figure
)除了使用熟悉的破折号样式外,此组件还允许用户在单个调用中扩展不同类型的跟踪(Plotly.extendTraces()
接受key:val映射,并假定所有跟踪都将共享相同的数据键)
代码
每秒扩展一次跟踪,限制为100个最大点。importdash_extendable_graphasdegimportdashfromdash.dependenciesimportInput,Output,Stateimportdash_html_componentsashtmlimportdash_core_componentsasdccimportrandomapp=dash.Dash(__name__)app.scripts.config.serve_locally=Trueapp.css.config.serve_locally=Trueapp.layout=html.Div([deg.ExtendableGraph(id='extendablegraph_example',figure=dict(data=[{'x':[0],'y':[0],'mode':'lines+markers'}],)),dcc.Interval(id='interval_extendablegraph_update',interval=1000,n_intervals=0,max_intervals=-1),html.Div(id='output')])@app.callback(Output('extendablegraph_example','extendData'),[Input('interval_extendablegraph_update','n_intervals')],[State('extendablegraph_example','figure')])defupdate_extendData(n_intervals,existing):x_new=existing['data'][0]['x'][-1]+1y_new=random.random()return[dict(x=[x_new],y=[y_new])],[0],100if__name__=='__main__':app.run_server(debug=True)
贡献
本地安装
- 依赖关系
$ npm install $ virtualenv venv $ . venv/bin/activate $ pip install -r requirements.txt $ pip install -r tests/requirements.txt
- 构建
$ npm run build
- 通过组件操场查看组件
$ npm run start
The demo app is in `src/demo`
- 使用组件查看示例Dash应用程序
$ python setup.py install $ python usage.py
测试
组件的集成测试可以在tests/
中找到
$pytest --headless tests
(注意:--headless
参数在没有gui的情况下运行测试)
创建生产版本并发布:
$ npm run build $ rm -rf dist $ python setup.py sdist bdist_wheel $ twine upload dist/* $ npm publish
通过将tarball复制到新环境中并在本地安装来测试它:
$ pip install dash_extendable_graph-X.X.X.tar.gz