2016-07-10 18 views
6

Ich probiere ein Beispiel Bokeh Application (in 'Single-Modul-Format') zum Generieren eines Diagramms aus einem Dataset. In diesem Beispiel kann der Benutzer auf der Webseite auf eine Schaltfläche klicken und das Diagramm wird mit den neuesten Daten aktualisiert. Ich versuche herauszufinden, wie ich das gleiche Verhalten erreichen kann, ohne dass der Benutzer auf die Schaltfläche klicken muss. Das heißt, ich möchte, dass das Diagramm automatisch in einem bestimmten Intervall aktualisiert/aktualisiert/neu geladen wird, ohne dass eine Benutzerinteraktion erforderlich ist. Im Idealfall müsste ich nur etwas in myapp.py ändern, um dies zu erreichen.Bokeh: Bokeh-Plots automatisch aktualisieren

Bokeh-Version ist 0.12.0.

Demo-Code hier der Einfachheit halber kopiert:

# myapp.py 

import numpy as np 

from bokeh.layouts import column 
from bokeh.models import Button 
from bokeh.palettes import RdYlBu3 
from bokeh.plotting import figure, curdoc 

# create a plot and style its properties 
p = figure(x_range=(0, 100), y_range=(0, 100), toolbar_location=None) 
p.border_fill_color = 'black' 
p.background_fill_color = 'black' 
p.outline_line_color = None 
p.grid.grid_line_color = None 

# add a text renderer to out plot (no data yet) 
r = p.text(x=[], y=[], text=[], text_color=[], text_font_size="20pt", 
      text_baseline="middle", text_align="center") 

i = 0 

ds = r.data_source 

# create a callback that will add a number in a random location 
def callback(): 
    global i 
    ds.data['x'].append(np.random.random()*70 + 15) 
    ds.data['y'].append(np.random.random()*70 + 15) 
    ds.data['text_color'].append(RdYlBu3[i%3]) 
    ds.data['text'].append(str(i)) 
    ds.trigger('data', ds.data, ds.data) 
    i = i + 1 

# add a button widget and configure with the call back 
button = Button(label="Press Me") 
button.on_click(callback) 

# put the button and plot in a layout and add to the document 
curdoc().add_root(column(button, p)) 

Antwort

Verwandte Themen