Hi,
Firstly, congrats on Dash. It’s one of the most exciting packages I’ve seen in ages, and although I’m not an expert Python programmer, I’ve already got something working which would have been way beyond me otherwise. It’s utterly brilliant and exciting to see where it develops.
One issue though: I just tried adapting the live update example, but no matter what I try, the sql result (using pymysql) doesn’t update in the callback. I’ve tried Pandas’ method directly - same issue.
The function to get new data using satellite = Orbital('TERRA')
works fine. Why would my very basic sql function not work in the same fashion?
Code:
def get_data():
cur = db.cursor(pymysql.cursors.DictCursor)
cur.execute(sql)
sql_results=cur.fetchall()
cur.close()
return sql_results
app = dash.Dash(__name__)
app.layout = html.Div(
html.Div([
html.H4('TERRA Satellite Live Feed'),
html.Div(id='live-update-text'),
dcc.Interval(
id='interval-component',
interval=1*10000 # in milliseconds
)
])
)
# The `dcc.Interval` component emits an event called "interval"
# every `interval` number of milliseconds.
# Subscribe to this event with the `events` argument of `app.callback`
@app.callback(Output('live-update-text', 'children'),
events=[Event('interval-component', 'interval')])
def update_metrics():
df = pd.DataFrame(get_data())
lon, lat, alt = satellite.get_lonlatalt(datetime.datetime.now())
print "lon",lon
print "df:",df['thecount'].iloc[0]
style = {'padding': '5px', 'fontSize': '16px'}
return [
html.Span('Longitude: {0}'.format(df['thecount'].iloc[0]), style=style)
]
update_metrics works fine. And get_data is called correctly too, but the result never changes. Related issue on Git: https://github.com/plotly/dash/issues/81
Thanks
Will