Black Lives Matter. Please consider donating to Black Girls Code today.

Stop streaming functionality

I was wondering whether it is possible to stop Plotly.extendTraces and keep the graphs intact with the last streamed data on the graphs? I am streaming data from a python server at the moment, and I want a way to stop data from being plotted on the streaming graph by a button click.

Code:

plotGraph('Dashboard', data, layout);

var cnt = 0;

var interval = setInterval(function () {

	var update = {
		x: [
			[time],
			[time],
			[time],
			[time],
			[time],
			[time],
		],
		y: [
			[incoming[3]],
			[incoming[12]],
			[incoming[6]],
			[incoming[10]],
			[incoming[1]],
			[incoming[8]],
		]
	}
	Plotly.extendTraces('Dashboard', update, [0, 1, 2, 3, 4, 5], 100);
	Plotly.relayout('Dashboard', 'xaxis.autorange', true);
	if (cnt === 100) clearInterval(interval);
}, 50);

Plotly doesn’t provide an easy way to do this, but calling clearInterval(interval); will effectively stop your streaming calls.

1 Like