【发布时间】:2019-02-07 23:38:26
【问题描述】:
由于 Dash 是用于制作基于 Web 的交互式图表的相当新的框架,因此对于初学者来说没有太多具体或详细的信息。就我而言,我需要使用回调函数更新一个简单的条形图。 即使服务器运行良好而没有提示任何错误,数据也不会在浏览器上呈现。
需要帮助整理和理解数据不呈现的原因。
import dash
from dash.dependencies import Output, Event
import dash_core_components as dcc
import dash_html_components as html
import plotly
import plotly.graph_objs as go
app = dash.Dash(__name__)
colors = {
'background': '#111111',
'background2': '#FF0',
'text': '#7FDBFF'
}
app.layout = html.Div( children = [
html.Div([
html.H5('ANNx'),
dcc.Graph(
id='cx1'
)
])
]
)
@app.callback(Output('cx1', 'figure'))
def update_figure( ):
return {
'data': [
{'x': ['APC'], 'y': [9], 'type': 'bar', 'name': 'APC'},
{'x': ['PDP'], 'y': [8], 'type': 'bar', 'name': 'PDP'},
],
'layout': {
'title': 'Basic Dash Example',
'plot_bgcolor': colors['background'],
'paper_bgcolor': colors['background']
}
}
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
标签: python callback plotly-dash