Hello!
I was wondering if someone could give me some guidance on updating data for a plotly dashboard without reloading the page.
Here is the simplest code to exemplify this issue.
{% block content %}
<body>
<div id="myDiv"><!-- Plotly chart will be drawn inside this DIV --></div>
</div>
</body>
{% endblock %}
{% block footer_scripts %}
<script type="text/javascript">
var myPlot = document.getElementById('myDiv'),
d3 = Plotly.d3,
N = 16,
x = d3.range(N),
y = d3.range(N).map( d3.random.normal() ),
data = [ { x:x, y:y, type:'scatter',
mode:'markers', marker:{size:16} } ],
layout = {
hovermode:'closest',
title:'Click on Points'
};
Plotly.newPlot('myDiv', data, layout);
I have a div with one graph. It is populated using random data. This example is taken more or less right from the plotly docs. Now to get data from the server I can replace the plotly data points with a jinja template and pass data from the backend; easy enough. However, if a user wants to filter the graph down (let’s say I had a on click to load more specific data for that data point), I would want to pass that request onto the backend (for me flask) and then return the new data. however, I am pretty sure this reloads the page as it is a POST. Can I get some pointers on not reloading the whole dashboard?
I am using flask and jinja2, but I would assume the principle applies to any web framework.
Thanks,
James
Tags: Flask, Jinja2, Full-Stack, Plotly, Best Practices