I'm trying to add a template to my code with Jinja but it sends me the error. What this program does is to graph in real time and I want to add a bit of design with CSS.
This is the code:
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
from flask import Flask, render_template
from flask import request, jsonify
X = deque(maxlen=20)
Y = deque(maxlen=20)
X.append(1)
Y.append(1)
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Graph(id='live-update-graph', animate=True),
dcc.Interval(
id='interval-component',
interval=3000,
n_intervals=0
)
]
)
@app.callback(Output('live-update-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph(n):
X.append(X[-1]+1)
Y.append(Y[-1]+(Y[-1]*random.uniform(-0.1,0.1)))
data = go.Scatter(
x = list(X),
y = list(Y),
name = 'Scatter',
mode = 'lines+markers'
)
return render_template('template.html', {'data':[data], 'layout': go.Layout(xaxis = dict(range=[min(X), max(X)]),
yaxis = dict(range=[min(Y), max(Y)]))})
if __name__ == '__main__':
app.run_server(debug=True)
Thank you. Regards.