【发布时间】:2021-12-15 07:51:08
【问题描述】:
我正在尝试将我的 Dash 应用程序设置为自动从带有 dcc.Interval 的数据框中使用的 .csv 文件中提取最新数据。错误代码没有提供详细的解释,也并不总是出现。我已经尝试过使用按钮和设置的 6 秒间隔,但结果似乎是一样的。 Dash 应用程序一开始运行良好,然后刷新几次,然后开始出现错误:
回调错误更新graph.figure
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
app = dash.Dash(__name__)
server = app.server
df = pd.read_csv('example.csv', encoding="WINDOWS-1252")
app.layout = html.Div([
dcc.Graph(id='graph'),
dcc.Interval(
id='interval-component',
interval=1*6000,
n_intervals=0
)
])
@app.callback(
Output('graph','figure'),
[Input('interval-component', 'n_intervals')]
)
def update_df(n):
updated_df = pd.read_csv('example.csv', encoding="WINDOWS-1252")
fig = px.scatter(updated_df, x='Date', y='Deviation', height=800)
fig.update_layout(
yaxis_tickformat = '.0%',
)
fig.update_xaxes(
rangeslider_visible=True,
rangeselector=dict(
)
)
return fig
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
标签: python pandas plotly plotly-dash