How to have a "static" real-time graph?

Apologize if “static” is not the correct word.
I am using Bokeh to stream the number of aircrafts in the sky at an updating rate of 10 seconds. I am scraping that number from https://www.flightradar24.com/ (the number is in top left corner).

That works fine, but if the user refreshes the browser the graph starts drawing from scratch and previous glyphs are lost. Is there a way to have the graph display a number of initial glyphs (e.g. glyphs for the current day) for all users who load the app url? What is the technical term for this by the way?

Here’s my code if anyone wants to play around with it:

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bs4 import BeautifulSoup

import requests

f=figure(x_range=(0,100),y_range=(0,20000))

source=ColumnDataSource(data=dict(x=[1],y=[12000]))

f.line(x=‘x’,y=‘y’,source=source)

def update():
r=requests.get(“https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77,-47.71&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=7200&gliders=1&stats=1”,
headers={‘User-Agent’: ‘Mozilla/5.0’})
c=r.json()
flights=(c[“full_count”])

new_data=dict(x=[source.data['x'][-1]+1],y=[flights])

print(source.data)
source.stream(new_data,rollover=1500)

curdoc().add_root(f)
curdoc().add_periodic_callback(update,1000)

``

Thanks!

I guess the data would have to be stored in a database and then served in the plot somehow?

···

On Thursday, September 15, 2016 at 9:25:41 AM UTC+2, Adi wrote:

Apologize if “static” is not the correct word.
I am using Bokeh to stream the number of aircrafts in the sky at an updating rate of 10 seconds. I am scraping that number from https://www.flightradar24.com/ (the number is in top left corner).

That works fine, but if the user refreshes the browser the graph starts drawing from scratch and previous glyphs are lost. Is there a way to have the graph display a number of initial glyphs (e.g. glyphs for the current day) for all users who load the app url? What is the technical term for this by the way?

Here’s my code if anyone wants to play around with it:

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bs4 import BeautifulSoup

import requests

f=figure(x_range=(0,100),y_range=(0,20000))

source=ColumnDataSource(data=dict(x=[1],y=[12000]))

f.line(x=‘x’,y=‘y’,source=source)

def update():
r=requests.get(“https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77,-47.71&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=7200&gliders=1&stats=1”,
headers={‘User-Agent’: ‘Mozilla/5.0’})
c=r.json()
flights=(c[“full_count”])

new_data=dict(x=[source.data['x'][-1]+1],y=[flights])

print(source.data)
source.stream(new_data,rollover=1500)

curdoc().add_root(f)
curdoc().add_periodic_callback(update,1000)

``

Thanks!

The plot starts from scratch on page reload because your data is not stored persistently. You are right, the use of a database (or perhaps a global list variable) to store values would be a solution. However, the plot update function should only read from that database, while another function (perhaps another script, or a threaded function) is filling data in the database.

This way, your plot is really just a view on what actually is in your database and hence can be even opened in several parallel sessions.

Artur

···

On Friday, September 16, 2016 at 4:04:30 PM UTC+2, Adi wrote:

I guess the data would have to be stored in a database and then served in the plot somehow?

On Thursday, September 15, 2016 at 9:25:41 AM UTC+2, Adi wrote:

Apologize if “static” is not the correct word.
I am using Bokeh to stream the number of aircrafts in the sky at an updating rate of 10 seconds. I am scraping that number from https://www.flightradar24.com/ (the number is in top left corner).

That works fine, but if the user refreshes the browser the graph starts drawing from scratch and previous glyphs are lost. Is there a way to have the graph display a number of initial glyphs (e.g. glyphs for the current day) for all users who load the app url? What is the technical term for this by the way?

Here’s my code if anyone wants to play around with it:

from bokeh.io import curdoc
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bs4 import BeautifulSoup

import requests

f=figure(x_range=(0,100),y_range=(0,20000))

source=ColumnDataSource(data=dict(x=[1],y=[12000]))

f.line(x=‘x’,y=‘y’,source=source)

def update():
r=requests.get(“https://data-live.flightradar24.com/zones/fcgi/feed.js?bounds=59.09,52.64,-58.77,-47.71&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=7200&gliders=1&stats=1”,
headers={‘User-Agent’: ‘Mozilla/5.0’})
c=r.json()
flights=(c[“full_count”])

new_data=dict(x=[source.data['x'][-1]+1],y=[flights])

print(source.data)
source.stream(new_data,rollover=1500)

curdoc().add_root(f)
curdoc().add_periodic_callback(update,1000)

``

Thanks!