本文整理汇总了Python中bokeh.models.Button.on_click方法的典型用法代码示例。如果您正苦于以下问题:Python Button.on_click方法的具体用法?Python Button.on_click怎么用?Python Button.on_click使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.models.Button
的用法示例。
在下文中一共展示了Button.on_click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modify_doc
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def modify_doc(doc):
source = ColumnDataSource(dict(x=[1, 2], y=[1, 1]))
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_glyph(source, Circle(x='x', y='y', size=20))
plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
button = Button(css_classes=['foo'])
def cb(event):
source.data=dict(x=[10, 20], y=[10, 10])
button.on_click(cb)
doc.add_root(column(button, plot))
示例2: root
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def root():
# add a button widget and configure with the call back
button = Button(label="Press Me")
button.on_click(scrape_prices(url))
p = make_hist(prices)
#layout = vform(button, p)
#script, div = embed.components(layout)
script, div = embed.components(p,button)
return render_template('histograms.html',script = script,div = div)
示例3: init_controls
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def init_controls(self):
btnStop = Button(label="Stop", type="danger")
btnStart = Button(label="Start", type="success")
btnStop.on_click(self.handle_btnStop_press)
btnStart.on_click(self.handle_btnStart_press)
curdoc().add_root(btnStop)
curdoc().add_root(btnStart)
sliderHPThreshold = Slider(start=0, end=500, value=100, step=1, title="High pass threshold")
sliderHPThreshold.on_change('value', self.onChangeHPThreshold)
curdoc().add_root(vplot(sliderHPThreshold))
示例4: run
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def run(doc):
fig = figure(title='random data', width=400, height=200, tools='pan,box_zoom,reset,save')
source = ColumnDataSource(data={'x': [], 'y': []})
fig.line('x', 'y', source=source)
def click(n=100):
source.data = {'x': range(n), 'y': random(n)}
button = Button(label='update', button_type='success')
button.on_click(click)
layout = column(widgetbox(button), fig)
doc.add_root(layout)
click()
示例5: root
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def root():
scrape_button = Button(label='Scrape Data')
prices = scrape_button.on_click(scrape_prices(url))
#prices = scrape_prices(url)
p = make_hist(prices)
script, div = embed.components(p,scrape_button)
return render_template('histograms.html',script = script,div = div)
示例6: do_step
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def do_step(document):
document.clear()
sl, c = next(examples)
p = plot_slice(sl)
b_A = Button(label="Accept")
b_R = Button(label="Reject")
b_A.on_click(functools.partial(callback, sl, c, 'accept'))
b_R.on_click(functools.partial(callback, sl, c, 'reject'))
plot = vplot(p, (hplot(b_A, b_R)))
document.add_root(plot)
示例7: modify_doc
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def modify_doc(doc):
plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0)
plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data"))))
table = DataTable(columns=[
TableColumn(field="x", title="x", sortable=True),
TableColumn(field="y", title="y", sortable=True)
], source=source, editable=False)
button = Button(css_classes=["foo"])
def cb():
source.stream({'x': [100], 'y': [100]})
button.on_click(cb)
doc.add_root(column(plot, table, button))
示例8: test_event_handles_new_callbacks_in_event_callback
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def test_event_handles_new_callbacks_in_event_callback(self):
from bokeh.models import Button
d = document.Document()
button1 = Button(label="1")
button2 = Button(label="2")
def clicked_1():
button2.on_click(clicked_2)
d.add_root(button2)
def clicked_2():
pass
button1.on_click(clicked_1)
d.add_root(button1)
event_json = json.dumps({"event_name":"button_click","event_values":{"model_id":button1.id}})
try:
d.apply_json_event(event_json)
except RuntimeError:
pytest.fail("apply_json_event probably did not copy models before modifying")
示例9: plot
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def plot():
import numpy as np
from bokeh.models import Button
from bokeh.palettes import RdYlBu3
from bokeh.plotting import figure, vplot
# create a plots 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 plots (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():
nonlocal 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)
plot_this = vplot(button, p)
return plot_this
示例10: line_scratch
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def line_scratch():
line_width = 4
line1 = [(0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)]
line2 = [(0, 1, 2, 3, 4, 5), (0, 5, 1, 4, 2, 3)]
line3 = [(5, 4, 3, 2, 1), (5, 4, 3, 2, 1)]
plot = figure()
red = plot.line(x=line1[0], y=line1[1], line_width=line_width, color="crimson")
blue = plot.line(x=line2[0], y=line2[1], line_width=line_width)
# purple = plot.line(x=line3[0], y=line3[1], line_width=line_width, color="purple")
button = Button(label="Add Line")
button.on_click(add_line)
curdoc().add_root(vplot(plot, button))
session = push_session(curdoc())
script = autoload_server(model=None, session_id=session.id)
# script, div = components(vplot(plot, button))
return script
示例11: Button
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
size = [20] * N
source1.data["size"] = size
session.store_objects(source1)
source2.on_change("selected", on_selection_change2)
reset = Button(label="Reset")
def on_reset_click():
source1.selected = {"0d": {"flag": False, "indices": []}, "1d": {"indices": []}, "2d": {"indices": []}}
source2.selected = {"0d": {"flag": False, "indices": []}, "1d": {"indices": []}, "2d": {"indices": []}}
session.store_objects(source1, source2)
reset.on_click(on_reset_click)
vbox = VBox(children=[reset], width=150)
hbox = HBox(children=[vbox, plot1, plot2])
document.add(hbox)
session.store_document(document)
if __name__ == "__main__":
link = session.object_link(document.context)
print("Please visit %s to see the plots" % link)
view(link)
print("\npress ctrl-C to exit")
session.poll_document(document)
示例12: len
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
if len(df_) == 0: # Bad constraints
status.text = 'No cases found. Try different constraints.'
return
doa = [not survived for survived in df_.survived]
kmf = KaplanMeierFitter()
fit = kmf.fit(df_.days, event_observed=doa, label='prob_of_surv')
# Here, we are using the smoothed version of the Kaplan-Meier curve
# The stepwise version would work just as well
data, surv_func = renderer.data_source.data, fit.survival_function_
data.update(x=surv_func.index, y=surv_func.prob_of_surv)
start, end = 0, max(df_.days)
# bounds='auto' doesn't work?
plot.x_range.update(start=start, end=end, bounds=(start, end))
status.text = '{} cases found.'.format(len(df_))
plot.xaxis.axis_label = 'Time (days)'
plot.yaxis.axis_label = 'Probability of Survival'
generate.on_click(generate_plot)
generate_plot() # Start with Hikers, both sexes, all ages and group sizes
document = curdoc()
document.add_root(vplot(plot, status, generate, selectors))
示例13: dict
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
source.data = dict(rx=rx, ry=ry)
source_short.data = dict(rx_short=rx_short, ry_short=ry_short)
source_far.data = dict(rx_far=rx_far, ry_far=ry_far)
# initialize data source
source = ColumnDataSource(data=dict(rx=[], ry=[]))
source_short = ColumnDataSource(data=dict(rx_short=[], ry_short=[]))
source_far = ColumnDataSource(data=dict(rx_far=[], ry_far=[]))
source_datatable = ColumnDataSource(data=dict(shot_alpha=[], shot_error=[]))
app_data = ColumnDataSource(data=dict(alpha=[bv_settings.alpha_init], alpha_left=[bv_settings.alpha_left],
alpha_right=[bv_settings.alpha_right]))
buttonShort = Button(label="shoot shorter")
buttonShort.on_click(shoot_shorter)
buttonFar = Button(label="shoot further")
buttonFar.on_click(shoot_further)
# initialize plot
toolset = "crosshair,pan,reset,resize,wheel_zoom,box_zoom"
# Generate a figure container
plot = Figure(plot_height=bv_settings.fig_height,
plot_width=bv_settings.fig_width,
tools=toolset,
title=bv_settings.title, # obj.text.value,
x_range=[bv_settings.min_x, bv_settings.max_x],
y_range=[bv_settings.min_y, bv_settings.max_y]
)
# Plot the line by the x,y values in the source property
plot.line('rx', 'ry',
示例14: BokehFileViewer
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
#.........这里部分代码省略.........
self.update_telid_widget()
self._channel = self.viewer.channel
self.update_channel_widget()
def update_dl1_calibrator(self, extractor=None, cleaner=None):
"""
Recreate the dl1 calibrator with the specified extractor and cleaner
Parameters
----------
extractor : ctapipe.image.charge_extractors.ChargeExtractor
cleaner : ctapipe.image.waveform_cleaning.WaveformCleaner
"""
if extractor is None:
extractor = self.dl1.extractor
if cleaner is None:
cleaner = self.dl1.cleaner
self.extractor = extractor
self.cleaner = cleaner
kwargs = dict(config=self.config, tool=self)
self.dl1 = CameraDL1Calibrator(
extractor=self.extractor,
cleaner=self.cleaner,
**kwargs
)
self.dl1.calibrate(self.event)
self.viewer.refresh()
def create_next_event_widget(self):
self.w_next_event = Button(label=">", button_type="default", width=50)
self.w_next_event.on_click(self.on_next_event_widget_click)
def on_next_event_widget_click(self):
self.event_index += 1
def create_previous_event_widget(self):
self.w_previous_event = Button(
label="<",
button_type="default",
width=50
)
self.w_previous_event.on_click(self.on_previous_event_widget_click)
def on_previous_event_widget_click(self):
self.event_index -= 1
def create_event_index_widget(self):
self.w_event_index = TextInput(title="Event Index:", value='')
def update_event_index_widget(self):
if self.w_event_index:
self.w_event_index.value = str(self.event_index)
def create_event_id_widget(self):
self.w_event_id = TextInput(title="Event ID:", value='')
def update_event_id_widget(self):
if self.w_event_id:
self.w_event_id.value = str(self.event_id)
def create_goto_event_index_widget(self):
self.w_goto_event_index = Button(
label="GOTO Index",
示例15: __init__
# 需要导入模块: from bokeh.models import Button [as 别名]
# 或者: from bokeh.models.Button import on_click [as 别名]
def __init__(self, n_nodes):
self.i = 0
kps = [crypto_sign_keypair() for _ in range(n_nodes)]
stake = {kp[0]: 1 for kp in kps}
network = {}
self.nodes = [Node(kp, network, n_nodes, stake) for kp in kps]
for n in self.nodes:
network[n.pk] = n.ask_sync
self.ids = {kp[0]: i for i, kp in enumerate(kps)}
self.main_its = [n.main() for n in self.nodes]
for m in self.main_its:
next(m)
def toggle():
if play.label == '► Play':
play.label = '❚❚ Pause'
curdoc().add_periodic_callback(self.animate, 50)
else:
play.label = '► Play'
curdoc().remove_periodic_callback(self.animate)
play = Button(label='► Play', width=60)
play.on_click(toggle)
def sel_node(new):
self.active = new
node = self.nodes[new]
self.tbd = {}
self.tr_src.data, self.links_src.data = self.extract_data(
node, bfs((node.head,), lambda u: node.hg[u].p), 0)
for u, j in tuple(self.tbd.items()):
self.tr_src.data['line_alpha'][j] = 1 if node.famous.get(u) else 0
if u in node.idx:
self.tr_src.data['round_color'][j] = idx_color(node.idx[u])
self.tr_src.data['idx'][j] = node.idx.get(u)
if u in node.idx and u in node.famous:
del self.tbd[u]
print('updated')
self.tr_src.trigger('data', None, self.tr_src.data)
selector = RadioButtonGroup(
labels=['Node %i' % i for i in range(n_nodes)], active=0,
name='Node to inspect')
selector.on_click(sel_node)
plot = figure(
plot_height=700, plot_width=900, y_range=(0, 30),
tools=[PanTool(dimensions=['height']),
HoverTool(tooltips=[
('round', '@round'), ('hash', '@hash'),
('timestamp', '@time'), ('payload', '@payload'),
('number', '@idx')])])
plot.xgrid.grid_line_color = None
plot.xaxis.minor_tick_line_color = None
plot.ygrid.grid_line_color = None
plot.yaxis.minor_tick_line_color = None
self.links_src = ColumnDataSource(data={'x0': [], 'y0': [], 'x1': [],
'y1': [], 'width': []})
#self.links_rend = plot.add_layout(
# Arrow(end=NormalHead(fill_color='black'), x_start='x0', y_start='y0', x_end='x1',
# y_end='y1', source=self.links_src))
self.links_rend = plot.segment(color='#777777',
x0='x0', y0='y0', x1='x1',
y1='y1', source=self.links_src, line_width='width')
self.tr_src = ColumnDataSource(
data={'x': [], 'y': [], 'round_color': [], 'idx': [],
'line_alpha': [], 'round': [], 'hash': [], 'payload': [],
'time': []})
self.tr_rend = plot.circle(x='x', y='y', size=20, color='round_color',
line_alpha='line_alpha', source=self.tr_src, line_width=5)
sel_node(0)
curdoc().add_root(row([widgetbox(play, selector, width=300), plot], sizing_mode='fixed'))