✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Plotly Dash Graph not refreshing automatically

Hi All,

I am looking for some help here. I created an live graph, reading data from my csv file.
Once i change the content of source csv file, automatic refresh is not happening. Instead if i refresh the browser it will update the graph.

Can you please provide me solution so it will directly update the graph without manual interventions.
Thanks in advance.

Code snippet:

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque
import pandas as pd

app = dash.Dash(name)
app.layout = html.Div(
[
html.H4(‘Stock_Data_Streaming’),
dcc.Graph(id=‘live-graph’, animate=True),
dcc.Interval(
id=‘graph-update’,
interval=1*100,
n_intervals=0
)
]
)

@app.callback(Output(‘live-graph’, ‘figure’),
[Input(‘graph-update’, ‘n_intervals’)])

def update_graph_ohlc(n):
#global X
#global Y
#X.append(X[-1]+1)
#Y.append(Y[-1]+Y[-1]*random.uniform(-0.1,0.1))

df = pd.read_csv('NIFTY_Data.csv')

X = df['Date']


data = go.Ohlc(x=df['Date'],
                open=df['Col_Open'],
                high=df['Col_High'],
                low=df['Col_Low'],
                close=df['Col_Close']
              )


layout = go.Layout(
                title = "OHLC Testing Chart",
                xaxis = dict(title = "Date"),
                yaxis = dict(title = "Values in K")
    )



return {'data': [data],'layout' : [layout]}

if name == ‘main’:
app.run_server()

Source Data:

Date,Col_Open,Col_High,Col_Low,Col_Close,Col_Volume
27/01/20 9:15,31110.55,31117.1,31007.8,31087.6,0
27/01/20 9:16,31077.05,31093.65,31074.85,31088,0
27/01/20 9:17,31093.55,31103.45,31077.9,31085.75,0
27/01/20 9:18,31089.35,31094.9,31061.75,31071.8,0
27/01/20 9:19,31075.1,31075.1,31043.25,31051.15,0
27/01/20 9:20,31057.75,31057.75,30998.35,31016.2,0
27/01/20 9:21,31012.4,31018.35,30992.5,30996.65,0
27/01/20 9:22,30997.25,31002.2,30969.4,30971.9,0
27/01/20 9:23,30973.2,30994,30970.6,30992.15,0
27/01/20 9:24,30991.8,30991.8,30934.15,30934.5,0