【发布时间】:2020-10-25 12:56:08
【问题描述】:
我创建了一个基于flask和dash python的仪表板
如何以指定的时间间隔刷新从另一个 .py 文件中提取的数据?
我有一个从 openweathermap API 返回数据的 weather_api.py 文件
我将其称为:
html.Div(children=[
html.Div(children=[html.Img(src="http://openweathermap.org/img/wn/{}@2x.png".format(WEATHER_API.icon))]),
html.Div(children=[html.H2("{} ".format(round(WEATHER_API.current_temperature))),
html.Span(["Data", html.Br()]),
html.Span("{}".format(WEATHER_API.weather_description))]),
])
])
在文件的开头我导入WEATHER_API - 然后它将引用变量,例如: html.Span("{}".format(WEATHER_API.weather_description))
我希望这些数据每次例如刷新一次。 10 分钟 - 现在它的工作原理是数据只是从头开始 - 一旦我运行 Dash,它只会从 API 中“拉”一次数据。是否有可能以某种方式设置 @callback 每 10 分钟从 WEATHER_API 检索数据 - 就像每 10 分钟启动 WEATHER_API.py 一样?
【问题讨论】:
标签: python flask plotly-dash