Hi all,
I’m new to Dash and Plotly and currently I’m facing this issue.
My goal is to plot live data on the app. I’m using REST based calls to obtain my data.
My app runs for a while and then starts throwing this error:
Exception happened during processing of request from ('127.0.0.1', 6600)
Traceback (most recent call last):
File "C:\Users\ _________\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 316, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Users\ _________\AppData\Local\Programs\Python\Python37-32\lib\socketserver.py", line 665, in process_request
t.start()
File "C:\Users\ _________\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 852, in start
_start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Here is my Current Code:
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly
import time
import requests
import warnings
import json
from datetime import datetime
import collections
app = dash.Dash()
#Boostrap CSS.
app.css.append_css({'external_url': 'https://codepen.io/amyoshino/pen/jzXypZ.css'})
colors = {
'background': '#111111',
'text1': '#7FDBFF',
'text': '#000000'
}
data={}
G1 = collections.deque(maxlen=10)
G2 = collections.deque(maxlen=10)
G3 = collections.deque(maxlen=10)
G4 = collections.deque(maxlen=10)
T = collections.deque(maxlen=10)
auth1 = ("..............",".......................")
def rValRESTLatest(param, mode, item = 'None'):
url = "https://" + "11.111.11.111" + ":" + "1111" + "/DataStoreValueLatest/" + param + ':' + item
warnings.filterwarnings("ignore")
r1 = requests.get(url, auth = auth1, verify = False)
for line1 in r1.iter_lines(decode_unicode=True):
if line1:
var1 = json.loads(line1)
a = var1[0]
if mode == 1:
b = float(a['value'])
return(b)
elif mode == 2:
b = str(a['value'])
return(b)
def dataManipulation(data):
for i in range(0,10):
G1.append(rValRESTLatest('TransVel',1,'R2D2'))
G2.append(rValRESTLatest('RotVel',1,'R2D2'))
G3.append(rValRESTLatest('BatteryStateOfCharge',1,'R2D2'))
G4.append(rValRESTLatest('CPUUse',1,'R2D2'))
T.append(datetime.now())
time.sleep(0.5)
data['g1']=list(G1)
data['g2']=list(G2)
data['g3']=list(G3)
data['g4']=list(G4)
data['t']=list(T)
return(data)
app.layout = html.Div(
html.Div([
html.H4('Graphing Interface'),
html.Div(id='live-update-text'),
dcc.Graph(id='live-update-graph'),
dcc.Interval(
id='interval-component',
interval=10*1000, # in milliseconds
n_intervals=0
)
])
)
@app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph_live(n):
f_data = dataManipulation(data)
# Create the graph with subplots
fig = plotly.tools.make_subplots(rows=4, cols=1, vertical_spacing=0.2)
fig['layout']['margin'] = {
'l': 30, 'r': 10, 'b': 30, 't': 10
}
fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'right'}
fig.append_trace({
'x': f_data['t'],
'y': f_data['g1'],
'name': 'Graph1',
'mode': 'lines+markers',
'type': 'scatter'
}, 1, 1)
fig.append_trace({
'x': f_data['t'],
'y': f_data['g2'],
'name': 'Graph2',
'mode': 'lines+markers',
'type': 'scatter'
}, 2, 1)
fig.append_trace({
'x': f_data['t'],
'y': f_data['g3'],
'name': 'Graph3',
'mode': 'lines+markers',
'type': 'scatter'
}, 3, 1)
fig.append_trace({
'x': f_data['t'],
'y': f_data['g4'],
'name': 'Graph4',
'mode': 'lines+markers',
'type': 'scatter'
}, 4, 1)
return fig
`if __name__ == '__main__':`
app.run_server(debug=True)
- I don’t understand why this is happening?
- Is there any documentation on dcc.Interval? I do not understand how n_intervals works.
Any help is appreciated. Thank you for the support in advance!