ここでは2つのデータセットの例を示します。それぞれをソースに設定する必要があります。最初のボタンはxとy = 1つの乱数のリストを与えるだけです。 2番目のボタンは0からmax(x)、max(y)までランダムサンプルをとり、それをプロットします。 うまくいけば、それはあなたにあなたが望むことをするテンプレートを与えるでしょうか?
import random
from bokeh.layouts import layout
from bokeh.io import curdoc
from bokeh.models.widgets import Button
from bokeh.plotting import figure, ColumnDataSource
""" widget updating function """
def update_button1():
# get random data on source 1
newdata = data_reform()
source1.data = newdata
def update_button2():
# allocates source 2 data to data 1
data = source1.data
newdata2 = expand_data(data)
source2.data = newdata2
""" create buttons and allocate call back functions """
button1 = Button(label="Press here to update source1", button_type="success")
button2 = Button(label="Press here to update source2 from source1 data",
button_type="success")
button1.on_click(update_button1)
button2.on_click(update_button2)
""" example functions that operate on our data """
def data_reform():
newdata = {'x':[random.randint(40,100)]*10, 'y':[random.randint(4,100)]*10}
return newdata
def expand_data(data):
max_x = max(data['x'])
max_y = max(data['y'])
if(max_x <20):
max_x = 20
if(max_y <20):
max_y = 20
data = {'x':random.sample(range(0,max_x),20),
'y':random.sample(range(0,max_y),20)}
return data
source1 = ColumnDataSource({'x':[40]*10,'y':[30]*10})
source2 = ColumnDataSource({'x':[0]*20,'y':[20]*20})
""" example plots to show data changing """
figure1 = figure(plot_width=250,
plot_height=200,
x_axis_label='x',
y_axis_label='y')
figure2 = figure(plot_width=250,
plot_height=200,
x_axis_label='x',
y_axis_label='y')
figure1.vbar(x='x', width=0.5, bottom=0,top='y',source=source1,
color="firebrick")
figure2.vbar(x='x', width=0.5, bottom=0,top='y',source=source2,
color="firebrick")
layout = layout([[figure1, figure2, button1, button2]])
curdoc().add_root(layout)
これにいくつかのコードを追加できますか?しかし、あるウィジェットの価値を得てそれを別のウィジェットに渡すことは間違いありません。 – Anthonydouc
@お小の宮キ、ここ数日、あなたの助けてくれてありがとう。これらの種類のものの良い例をオンラインで見つけるのは難しいようです。現在のバージョンのコードは http://pastebin.com/b9Zs53jj githubには2つの入力ファイルをアップロードできません。サイズが大きすぎるため、必要な場合はお知らせください。コードには現在何もしていないテキストボックスウィジェットが追加されていますが、将来はそれが無視されます。再度、感謝します! – Kyle
私の回答があなたに役立っていて正しかった場合は、アップフォートして正しいとマークできますか?ありがとう:) – Anthonydouc