The flask utility underneath makes ajax calls indefinitely to a back-cease index characteristic which queries an information base and injects results into the template.
I'm waiting for that, after ajax is finished, the injected information may be refreshed hence updating the plot but it's now not.
The way to replace ajax in a manner that refreshes the injected records into 'index.Html' (subsequently updating plot which consumes those records)?
HTML code:-
<div class="card-body">
<div class="chart-area">
<div id = 'load' class = 'chart' style = 'height:100%'></div> <!--This is where chart appears -->
</div>
</div>
Jquery code:-
<script>
$(document).ready(function(){
function ajaxCall(){
$.ajax({
async: false,
type: 'POST',
url: '/',
dataType: 'json',
contentType: 'application/json;charset=UTF-8',
success: function (data) {
??? perhaps something here???
}
});
}
setInterval(ajaxCall, 2000); // repeatedly calls ajaxCall()
var graphs = {{graphJSON | safe}}; // saves injected data to variable
Plotly.plot('load',graphs,{}); // passes saved variable to Python function for plotting which then appears in div with 'load' id above.
});
</script>
Flask code:-
from flask import render_template, Blueprint,
from App.functions.reddit_streamer import AWS_RDB
import json
import plotly
import plotly.express as px
core = Blueprint('core', __name__)
@core.route('/', methods = ['GET', 'POST'])
def index():
db = AWS_RDB()
df = db.query_half_hour()
fig = px.line(df.loc[1:,:], x = 'date' , y = '# of comments')
graphJSON = json.dumps(fig, cls = plotly.utils.PlotlyJSONEncoder)
return render_template('index.html', graphJSON = graphJSON)
0 Replies