Python 虚线/绘图仪不';从树莓皮上跑步时不显示
我正在尝试将实时数据从树莓Pi绘制到web服务器。在本例中,我使用dash()来实现这一点。我目前正在mac上的静态数据上测试我的dash web浏览器,到目前为止,它工作正常。除了一条关于plotly的弃用消息,以及一条关于logger“werkzeug”找不到处理程序的消息之外,它工作得非常好。但是当我试图在我的raspberry Pi上运行完全相同的脚本时,我遇到了问题 在我的raspberry Pi上,web服务器运行,我可以在本地主机上打开它,但是图表是空的!!!我没有收到任何错误消息或发生这种情况的原因 编辑:添加脚本Python 虚线/绘图仪不';从树莓皮上跑步时不显示,python,linux,raspberry-pi,plotly-dash,werkzeug,Python,Linux,Raspberry Pi,Plotly Dash,Werkzeug,我正在尝试将实时数据从树莓Pi绘制到web服务器。在本例中,我使用dash()来实现这一点。我目前正在mac上的静态数据上测试我的dash web浏览器,到目前为止,它工作正常。除了一条关于plotly的弃用消息,以及一条关于logger“werkzeug”找不到处理程序的消息之外,它工作得非常好。但是当我试图在我的raspberry Pi上运行完全相同的脚本时,我遇到了问题 在我的raspberry Pi上,web服务器运行,我可以在本地主机上打开它,但是图表是空的!!!我没有收到任何错误消息
import os, sys
from pathlib import Path
currDir = Path(os.path.abspath(__file__))
_rootDir = currDir.parent.parent
# _dataDir = str(_rootDir / 'GridBallast-RaspberryPI' / 'data')
_dataDir = str(_rootDir / 'data')
import ETL
import datetime
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly
from dash.dependencies import Input, Output
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(
html.Div([
html.H4('RaspberryPI Sensor Charts'),
html.Div(id='live-update-text'),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=1*1000, # in milliseconds
n_intervals=0
)
])
)
@app.callback(Output('live-update-text', 'children'),
[Input('interval-component', 'n_intervals')])
def update_metrics(n):
Temperature, Time = ETL.extractLastTemp(os.path.join(_dataDir, 'tempData.csv'))
style = {'padding': '2px', 'fontSize': '16px'}
return [
html.Span('Temperature: {}'.format(Temperature), style=style),
html.Span('Time: {}'.format(Time), style=style)
]
@app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph_live(n):
#Load Temp Data
tempDict = ETL.etlTransform(os.path.join(_dataDir, 'tempData.csv'))
lightDict = ETL.etlTransform(os.path.join(_dataDir, 'lightData.csv'))
currentDict = ETL.etlTransform(os.path.join(_dataDir, 'currentData.csv'))
# Create the graph with subplots
fig = plotly.tools.make_subplots(rows=3, cols=1, vertical_spacing=0.2, subplot_titles=("Temperature", "Light", "Current"))
fig['layout']['margin'] = {
'l': 30, 'r': 10, 'b': 30, 't': 25
}
fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'}
fig['layout']['height'] = 900
fig.append_trace({
'x': tempDict.keys(),
'y': tempDict.values(),
'name': 'Temp vs. Time',
'mode': 'lines+markers',
'type': 'scatter'
}, 1, 1)
fig.append_trace({
'x': lightDict.keys(),
'y': lightDict.values(),
# 'text': data['time'],
'name': 'Light vs. Time',
'mode': 'markers',
'type': 'scatter'
}, 2, 1)
fig.append_trace({
'x': currentDict.keys(),
'y': currentDict.values(),
# 'text': data['time'],
'name': 'Current vs. Time',
'mode': 'markers',
'type': 'scatter'
}, 3, 1)
return fig
def main():
app.run_server(debug = True)
if __name__ == '__main__':
print(_dataDir)
print(os.listdir(_dataDir))
main()
# app.run_server(debug=True)
所以我可以通过增加更新间隔来解决这个问题。我猜在raspberry Pi上,间隔需要更大才能正确更新图表。很奇怪,但它是有效的 你能发布你的密码吗?此外,pi与mac具有相同的静态数据和文件结构,对吗?是的,文件结构相同。我之所以知道这一点,是因为我打印了一个os.listdir(_dataDir),它会返回预期的结果,即_dataDir目录中的数据文件列表。您的
pi
是否可以访问internet?在update\u graph\u live
功能中打印(tempDict、lightDict、currentDict)后,是否可以打印(tempDict、lightDict、currentDict)
,以确保它具有数据?请将其简化为一个,即每个人都可以抓取并运行以查看您的问题。另外,在raspberry pi上运行该命令与数据来自何处有何关系?最后,请在应用标记之前阅读标记说明,例如,使用“linux”标记表明您没有。@MasonCaiby Yes打印字典在update\u graph\u live功能中工作正常。但在线图表保持不变。我还认为可能数据文件包含了太多的条目,所以我让它们只包含了几个条目。这些解决方案都不起作用。我还要补充的是,该选项卡正在持续“更新…”,而在mac上,该选项卡在读取“破折号”和“更新…”之间交替。RPI版本似乎从未在浏览器中更新。