1

I am trying to chart real time data from a Raspberry Pi to a web server. In this case I am using dash (https://dash.plot.ly/live-updates) to do this. I am currently testing my dash web browser on static data on my mac, and so far it works just fine. Aside from a deprecation message about plotly, and a No Handlers could be found for logger "werkzeug", it works completely fine. BUT when I try to run the exact same script on my raspberry Pi, I hit problems.

On my raspberry Pi, the web server runs, I can open it up on localhost, but the charts are empty!!! I get no error messages or reasons why this is happening!

On Raspberry Pi

Whereas I need it to look like this. Below is what appears when I run the exact same script on my desktop.

Any Dash/Plotly or graphing wizards know why this could be happening?? Thank you!!!

enter image description here

Here is my entire script:

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)
]


# Multiple components can update everytime interval gets fired.
@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': main() # app.run_server(debug=True)

2
  • same data in _dataDir folder on both RPI and Mac?
    – abolotnov
    Oct 9, 2019 at 5:27
  • Yes I dont believe its a pathing issue.....I print an os.listdir(_dataDir) to see if it can find the directory and print out its contents.....it does.... Oct 9, 2019 at 15:24

1 Answer 1

1

so I was able to fix the issue by increasing the update interval. I guess on raspberry Pi, the interval needs to be larger in order for the chart to update correctly. Weird, but it works.

Looks like its an ongoing issue with Dash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.