简体   繁体   中英

Plotly in Dash Python is not getting updated

When I run the code i get the graph but the graph is not getting updated i am calling the data from my sql laptop sql management studio.

Kindly let me know what needs to be done the X axis contains date and time and Y axis contains data in numeric form which is getting updated automatically

Code:

import pandas as pd
import pyodbc
import numpy as np

server ='LAPTOP-OO3V36UA\SQLEXPRESS'
db='addy'

conn=pyodbc.connect('DRIVER={SQL Server}; SERVER=' +server + ';DATABASE=' + db + 
';Trusted_connection=yes')

 sql="""

 SELECT * FROM Summry

"""

 df=pd.read_sql(sql ,conn)

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
 from random import random
import plotly

app = dash.Dash(__name__)
app.layout = html.Div([
    dcc.Graph(id='live-update-graph-scatter', animate=True),
    dcc.Interval(
        id='interval-component',
        interval=1*1000
    )
])

@app.callback(Output('live-update-graph-scatter', 'figure'),
          [Input('interval-component', 'interval')])

def update_graph_scatter():

df=pd.read_sql(sql ,conn)
trace1=go.Scatter(
y=df['ACL'],
x = df['DateandnTime'],
mode='lines',
name='ACL'

)
layout = go.Layout(
title='Daily Monitoring'
)
return {'data': trace1, 'layout': layout}
if __name__ == '__main__':
app.run_server()

You've set your callback's input to

Input('interval-component', 'interval')

But you want

Input('interval-component', 'n_intervals')

The interval property sets how frequently n_intervals gets updated. The change in n_intervals is what can be used to trigger the callback.

Here's the documentation: https://dash.plotly.com/dash-core-components/interval

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM