2016-07-10 2 views
6

데이터 세트에서 차트를 생성하기 위해 Bokeh Application ('단일 모듈 형식') 예제를 사용하고 있습니다. 주어진 예제에서 웹 페이지의 사용자는 버튼을 클릭 할 수 있으며 차트는 최신 데이터로 업데이트됩니다. 사용자가 버튼을 클릭하지 않아도 동일한 동작을 어떻게 달성 할 수 있는지 파악하려고합니다. 즉, 사용자 상호 작용없이 지정된 간격으로 차트를 자동으로 업데이트/새로 고침/새로 고침하고 싶습니다. 이상적으로, 나는 이것을 달성하기 위해 단지 myapp.py에서 무엇인가를 변경해야 할 것이다.Bokeh : 자동으로 보케 플롯 새로 고침

bokeh 버전은 0.12.0입니다.

add_periodic_callback(callback, period_milliseconds)

확실하지 이유는 API의 외부에 언급되지 않습니다 편의를 위해 여기에 복사

데모 코드 : 문서 객체의 메서드 거기에서

# 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)) 

답변

관련 문제