Live Streaming doesn't appear


#1

Dear all,

I wanted to try live streaming with Dash, using Jena Climate dataset.

Here’s my code:

import dash
import dash_html_components as html
import dash_core_components as dcc
import pandas as pd
from dash.dependencies import Input, Output, State, Event
import os
import sqlite3
import pandas as pd
import plotly.plotly as py
from plotly.graph_objs import *

app = dash.Dash(‘wind-speed-app’)
server = app.server

app.layout = html.Div([html.Div([html.H2(“Wind Speed Streaming”)], className=‘banner’),
html.Div([html.Div([html.H3(“Wind Speed (m/s)”)], className=‘Title’),
html.Div([dcc.Graph(id=‘wind-speed’)], className=‘column wind-speed’),
dcc.Interval(id=‘wind-speed-update’,interval = 1000, n_intervals =0)
],className = ‘row wind-speed-row’)
])
@app.callback(Output(‘wind-speed’,‘figure’),
[Input(‘wind-speed-update’,‘n_intervals’)])
def gen_wind_speed(interval):
con = sqlite3.connect(“jena-climate.db”)
df = pd.read_sql_query(“SELECT wind_velocity from Jena_Climate”, con)
trace = Scatter(y=df[‘wind_velocity’],
line = Line(color = ‘#42C4F7’),
hoverinfo = ‘skip’,
mode = ‘lines’)
layout = Layout(height = 450,
xaxis=dict(range=[0,240],
showgrid=False,
showline=False,
zeroline=False,
fixedrange=True,
tickvals=[0, 60, 120, 180, 240],
ticktext=[‘240’, ‘180’, ‘120’, ‘60’, ‘0’],
title=‘Time elapsed (every 10 minutes)’),
yaxis=dict(range=[min(0, min(df[‘Speed’])), max(30, max(df[‘Speed’]))],showline=False,fixedrange=True,zeroline=False),
margin=Margin(t=45,l=50,r=50))
return Figure(data=[trace],layout=layout)
external_css = [“https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css”,
https://cdn.rawgit.com/plotly/dash-app-stylesheets/737dc4ab11f7a1a8d6b5645d26f69133d97062ae/dash-wind-streaming.css”,
https://fonts.googleapis.com/css?family=Raleway:400,400i,700,700i”,
https://fonts.googleapis.com/css?family=Product+Sans:400,400i,700,700i”]

for css in external_css:
app.css.append_css({“external_url”: css})

if ‘DYNO’ in os.environ:
app.scripts.append_script({
‘external_url’: ‘https://cdn.rawgit.com/chriddyp/ca0d8f02a1659981a0ea7f013a378bbd/raw/e79f3f789517deec58f41251f7dbb6bee72c44ab/plotly_ga.js
})

if name == ‘main’:
app.run_server(debug=True)
`
Anyone know where it went wrong? I dont know why the data doesnt appear… Any help is appreciated… Thanks


#2

Hey @munziliashali

Any error messages? Is the path to the to your db file correct?


#3

Hi @bcd
The message is like this:

127.0.0.1 - - [16/Jul/2018 11:09:21] “GET / HTTP/1.1” 200 -
127.0.0.1 - - [16/Jul/2018 11:09:22] “GET /_dash-layout HTTP/1.1” 200 -
127.0.0.1 - - [16/Jul/2018 11:09:22] “GET /_dash-dependencies HTTP/1.1” 200 -
[2018-07-16 11:09:22,916] ERROR in app: Exception on /_dash-update-component [POST]
Traceback (most recent call last):
File “C:\Users\Octo\Anaconda3\lib\site-packages\pandas\core\indexes\base.py”, line 2525, in get_loc
return self._engine.get_loc(key)
File “pandas/_libs/index.pyx”, line 117, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/index.pyx”, line 139, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 1265, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 1273, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘Speed’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask\app.py”, line 1982, in wsgi_app
response = self.full_dispatch_request()
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask\app.py”, line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask\app.py”, line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask_compat.py”, line 33, in reraise
raise value
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask\app.py”, line 1612, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Users\Octo\Anaconda3\lib\site-packages\flask\app.py”, line 1598, in dispatch_request
return self.view_functionsrule.endpoint
File “C:\Users\Octo\Anaconda3\lib\site-packages\dash\dash.py”, line 556, in dispatch
return self.callback_map[target_id]‘callback’
File “C:\Users\Octo\Anaconda3\lib\site-packages\dash\dash.py”, line 513, in add_context
output_value = func(*args, **kwargs)
File “”, line 28, in gen_wind_speed
yaxis=dict(range=[min(0, min(df[‘Speed’])), max(30, max(df[‘Speed’]))],

I’m certain the path is correct


#4

Hi there,

Thanks for pasting your traceback

df = pd.read_sql_query(“SELECT wind_velocity from Jena_Climate”, con)

Looks like you’re only selecting wind_velocity but later on in yaxis referencing df['Speed']


#5

Hi @charleyferrari
Thank you, you are right. I fixed it, though and the error msg is gone. However, the live stream still doesnt appear even though the msg looks like it’s updating the callback.

  • Running on http://0.0.0.0:9999/ (Press CTRL+C to quit)
    127.0.0.1 - - [17/Jul/2018 09:33:09] “GET / HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:10] “GET /_dash-layout HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:10] “GET /_dash-dependencies HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:13] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:14] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:16] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:18] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:20] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:23] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:26] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:28] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:31] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:33] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:35] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:39] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:42] “POST /_dash-update-component HTTP/1.1” 200 -
    127.0.0.1 - - [17/Jul/2018 09:33:44] “POST /_dash-update-component HTTP/1.1” 200