当前位置: 首页>>代码示例>>Python>>正文


Python Button.on_click方法代码示例

本文整理汇总了Python中bokeh.models.widgets.Button.on_click方法的典型用法代码示例。如果您正苦于以下问题:Python Button.on_click方法的具体用法?Python Button.on_click怎么用?Python Button.on_click使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bokeh.models.widgets.Button的用法示例。


在下文中一共展示了Button.on_click方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mass_plotting

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
	def mass_plotting(self, filename):


		data_dict = self.data_generation(filename)
		self.data_test(data_dict)
		name_check = data_dict["gen_info"]["DATA FILES"]
		attr_id = name_check[1][4][:-3] + "_" + name_check[2][2]

		TOOLS="pan,wheel_zoom,box_zoom,reset, hover, previewsave"
		figure_obj = figure(plot_width = 1000, plot_height = 800, y_axis_type = "log",
			title = attr_id, tools = TOOLS)

		figure_obj.yaxis.axis_label = data_dict["data"][0]["y_unit"]
		figure_obj.xaxis.axis_label = data_dict["data"][0]["x_unit"]

		hover = figure_obj.select(dict(type = HoverTool))
		hover.tooltips=[("Value:", "$top")]

		hist, edges = np.histogram(data_dict["data"][0]["y"],  bins = data_dict["data"][0]["x"])
		source = ColumnDataSource(data = dict(top = hist, left = edges[:-1], right = edges[1:], 
					x_unit = data_dict["data"][0]["x_unit"], y_unit = data_dict["data"][0]["y_unit"],
					edges = edges))
		#hist = figure_obj.Histogram(source )
		figure_obj.quad(top = "top", bottom = 0, left = "left" , right = "right", source = source)

		matplot_button = Button(label = "create matplotlib plot")

		matplot_button.on_click(lambda source_list = source:
							self.matplotlib_export_ms(source_list))


		return Panel(child = hplot(figure_obj, matplot_button), title = attr_id)
开发者ID:copperwire,项目名称:cephalopod,代码行数:34,代码来源:interactive_plotting.py

示例2: read_file_tab

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
    def read_file_tab(self):

        """Lets the user choose a data file to read"""

        # Drop down list
        self.file_select = Select(name='Data files',
                                  value='',
                                  options=[],
                                  title='Data files')
        # Status text
        self.file_status = Div(text='', width=self.page_width)

        # Update the file_select and file_status controls with scan data
        self.scan_folder()

        # This line is here deliberately. The scan_folder would trigger
        # the on-change function and we don't want that first time around.
        self.file_select.on_change('value', self.file_changed)

        # Re-scan button
        file_rescan = Button(label="Rescan folder", button_type="success")
        file_rescan.on_click(self.scan_folder)

        # Layout
        c = column(self.file_select,
                   self.file_status,
                   file_rescan)

        return Panel(child=c, title="Read from file")
开发者ID:MikeWoodward,项目名称:UT330B,代码行数:31,代码来源:UI.py

示例3: Offsets_Panel

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
class Offsets_Panel(object):

    def __init__(self, ut330):

        self.ut330 = ut330

        self.t_current = TextInput(title="Temperature current")
        self.h_current = TextInput(title="Humidity current")
        self.p_current = TextInput(title="Pressure current")

        self.t_offset = TextInput(title="Temperature offset")
        self.h_offset = TextInput(title="Humidity offset")
        self.p_offset = TextInput(title="Pressure offset")

        self.read_offsets = Button(label='Read offsets')
        self.write_offsets = Button(label='Write offsets')

    def _layout_(self):
        return VBox(HBox(self.t_current, self.t_offset, width=500),
                    HBox(self.h_current, self.h_offset, width=500),
                    HBox(self.p_current, self.p_offset, width=500),
                    HBox(self.read_offsets, self.write_offsets, width=500))

    def panel(self):

        return Panel(child=self._layout_(), title="Offsets")

    def _read_(self):

        offsets = self.ut330.read_offsets()

        self.t_current.value = str(offsets['temperature'])
        self.h_current.value = str(offsets['humidity'])
        self.p_current.value = str(offsets['pressure'])

        self.t_offset.value = str(offsets['temperature offset'])
        self.h_offset.value = str(offsets['humidity offset'])
        self.p_offset.value = str(offsets['pressure offset'])

    def _write_(self):

        offsets = {'temperature offset': float(self.t_offset.value),
                   'humidity offset': float(self.h_offset.value),
                   'pressure offset': float(self.p_offset.value)}

        self.ut330.write_offsets(offsets)

    def callbacks(self):

        self.read_offsets.on_click(self._read_)
        self.write_offsets.on_click(self._write_)

    def device_read(self):

        self._read_()
开发者ID:MikeWoodward,项目名称:UT330B,代码行数:57,代码来源:Offsets_Panel.py

示例4: make_layout

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
def make_layout():
    plot, source = make_plot()
    columns = [
        TableColumn(field="dates", title="Date", editor=DateEditor(), formatter=DateFormatter()),
        TableColumn(field="downloads", title="Downloads", editor=IntEditor()),
    ]
    data_table = DataTable(source=source, columns=columns, width=400, height=400, editable=True)
    button = Button(label="Randomize data", button_type="success")
    button.on_click(click_handler)
    buttons = WidgetBox(children=[button],width=800)
    column = Column(children=[buttons, plot, data_table])
    return column
开发者ID:NamiStudio,项目名称:bokeh,代码行数:14,代码来源:widgets_server.py

示例5: make_layout

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
def make_layout():
    plot, source = make_plot()
    columns = [
        TableColumn(field="dates", title="Date"),
        TableColumn(field="downloads", title="Downloads"),
    ]
    data_table = DataTable(source=source, columns=columns, width=400, height=400)
    button = Button(label="Randomize data", type="success")
    button.on_click(click_handler)
    buttons = VBox(children=[button])
    vbox = VBox(children=[buttons, plot, data_table])
    return vbox
开发者ID:RamonMF,项目名称:bokeh,代码行数:14,代码来源:widgets_server.py

示例6: time_tab

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
    def time_tab(self):

        """The date and time setting and getting tab"""

        self.time_status = Div(text="", width=self.page_width)

        time_connect = Button(label='Connect to UT330',
                              button_type="success")

        time_disconnect = Button(label='Disconnect from UT330',
                                 button_type="success")

        time_get = Button(label='Get UT330 date and time',
                          button_type="success")

        self.time_compare = Div(text="", width=self.page_width)

        time_set = Button(label='Set the UT330 date and time',
                          button_type="success")

        time_connect.on_click(self.time_connect)
        time_disconnect.on_click(self.time_disconnect)
        time_get.on_click(self.time_get)
        time_set.on_click(self.time_set)

        l = layout([self.time_status],
                   [time_connect, time_disconnect],
                   [time_get, self.time_compare],
                   [time_set])

        return Panel(child=l, title="Date and time setting")
开发者ID:MikeWoodward,项目名称:UT330B,代码行数:33,代码来源:UI.py

示例7: device_data_tab

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
    def device_data_tab(self):

        """Reading device data"""
        self.data_status = Div(text="", width=self.page_width)

        data_connect = Button(label='Connect to UT330',
                              button_type="success")
        data_read = Button(label='Read data',
                           button_type="success")
        data_write = Button(label='Write data to disk',
                            button_type="success")
        data_erase = Button(label='Erase data',
                            button_type="success")
        data_disconnect = Button(label='Disconnect from UT330',
                                 button_type="success")

        data_connect.on_click(self.data_connect)
        data_read.on_click(self.data_read)
        data_write.on_click(self.data_write)
        data_erase.on_click(self.data_erase)
        data_disconnect.on_click(self.data_disconnect)

        if self.device_connected:
            self.data_status.text = ('UT330 device connected. The Read, '
                                     'Write, Erase, and Disconnect buttons '
                                     'will work.')
        else:
            self.data_status.text = ('UT330 device is <strong>NOT</strong> '
                                     'connected. The '
                                     'Read, Write, Erase, and Disconnect '
                                     'buttons will <strong>not work</strong>. '
                                     'Press the '
                                     'Connect button if the UT330 is '
                                     'connected on a USB port.')

        # Layout
        l = layout([[self.data_status],
                    [data_connect, data_disconnect],
                    [data_read, data_write, data_erase]],
                   width=self.page_width)

        return Panel(child=l,
                     title="Read from device")
开发者ID:MikeWoodward,项目名称:UT330B,代码行数:45,代码来源:UI.py

示例8: get_reconstruction

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
    v0_value = v0.value
    v1_value = v1.value
    v2_value = v2.value
    v3_value = v3.value

    # Generate the new curve
    m_projection = [v0_value, v1_value, v2_value, v3_value]
    rec = get_reconstruction(m_eigs_t, m_projection, m_mean_vector)
    x = [i for i in xrange(np.shape(rec)[0])]
    y = [v for v in rec]

    source.data = dict(x=x, y=y)

def on_click(*args):
    m_projection = [0., 0., 0., 0.]
    rec = get_reconstruction(m_eigs_t, m_projection, m_mean_vector)
    x = [i for i in xrange(np.shape(rec)[0])]
    y = [v for v in rec]

    source.data = dict(x=x, y=y)


for w in [v0, v1, v2, v3]:
    w.on_change('value', update_data)
button.on_click(on_click)

# Set up layouts and add to document
inputs = HBox(children=[v0, v1, v2, v3, button])

curdoc().add_root(VBox(children=[inputs, plot], width=1200))
开发者ID:conwaywong,项目名称:dse_capstone,代码行数:32,代码来源:eigenvector_analysis.py

示例9: Toggle

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
toggle = Toggle(label="Start", type="success")
toggle.on_click(toggle_handler)
toggle.active = False

# Set up reset button
def reset_handler():
    global ii, current_time
    ii = 0
    current_time = 0
    l_forward.data_source.data["y"] = forward_wave()
    l_reverse.data_source.data["y"] = reverse_wave()
    l_sum.data_source.data["y"] = l_forward.data_source.data["y"] + \
                                  l_reverse.data_source.data["y"]
    #t2.data_source.data["text"] = ['t = {:.3f} s'.format(current_time)]
button_reset = Button(label="Reset", type="success")
button_reset.on_click(reset_handler)

# Set up checkboxes to show/hide forward & reverse propagating waves
def checkbox_group_handler(active):
    global alpha, alpha_slider
    if 0 in active:
        #l_forward.glyph.visible = True
        l_forward.glyph.line_alpha = alpha_forward_reverse_waves
    else:
        #l_forward.glyph.visible = False
        l_forward.glyph.line_alpha = 0.0
    if 1 in active:
        #l_reverse.glyph.visible = True
        l_reverse.glyph.line_alpha = alpha_forward_reverse_waves
    else:
        #l_reverse.glyph.visible = False
开发者ID:gregnordin,项目名称:ECEn360_Winter2016,代码行数:33,代码来源:sinusoidal_wave_animation.py

示例10: on_selection_change

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
date_slider.on_change("value", update)
time_slider.on_change("value", update)
type_button.on_change("active", update)

def on_selection_change(attr, old, new):
    print("on_selection_change")
    indices = new["1d"]["indices"]
    if indices:
        sector_id = geo_sectors.loc[indices[0]]["sector_id"]
        sector_select.value = str(sector_id) # Calls update in chain
        #update_sources(sector_id=sector_id)
map_plot.get_data_source().on_change("selected", on_selection_change)

def close_session():
    session.close()
button.on_click(close_session)


# Page build
inputs = VBoxForm(children=[sector_select, date_slider, time_slider,
                            type_button])
map_box = HBox(children=[map_colorbar.get_plot(), map_plot.get_plot()])
plots = VBox(children=[map_box, conso_plot.get_plot()])
root_element = HBox(children=[inputs, plots])

update(None, None, None) # Init data


# Session
print("Starting server")
curdoc().add_root(root_element)
开发者ID:alex-marty,项目名称:demo-eau,代码行数:33,代码来源:main.py

示例11: push_session

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
session = push_session(curdoc())

def start_handler():
    global playing
    if not playing:
        curdoc().add_periodic_callback(update, 50)
        playing = True

def stop_handler():
    global playing
    if playing:
        curdoc().remove_periodic_callback(update)
        playing = False

button_start = Button(label="Start", button_type="success")
button_start.on_click(start_handler)

button_stop = Button(label="Stop", button_type="danger")
button_stop.on_click(stop_handler)

controls = hplot(button_start, button_stop)
layout = vplot(controls, p)

@cosine(w=0.03)
def update(step):
    if playing:
        r2.data_source.data["y"] = y * step
        r2.glyph.line_alpha = 1 - 0.8 * abs(step)

playing = True
curdoc().add_periodic_callback(update, 50)
开发者ID:0-T-0,项目名称:bokeh,代码行数:33,代码来源:line_animate_widget.py

示例12: plot

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
def plot():

    # INPUT WIDGETS
    collection_list = ['bugaboo']
    #collection_list = util.CONN[util.DB].collection_names(include_system_collections=False)
    gliders = sorted([platformID for platformID in collection_list if len(platformID)>2])
    gliders = Select(title = 'PlatformID', value = gliders[0], options = gliders)
    prev_glider = Button(label = '<')
    next_glider = Button(label = '>')
    glider_controlbox = HBox(children = [gliders, prev_glider, next_glider])

    control_box = HBox(glider_controlbox)

    # DATA VARS
    heatdata = dict(x=[1.5,2],y=[2,1.5],values=[0,10])
    t = 1000*util.time()
    heatdata = dict(x=[t-4*60*1000,t-3*60*1000,t-2*60*1000,t-1*60*1000],
                    y=[1,1,2,2], values=[1,2,3,4])

    # FIGURES AND AXIS
    fig1 = HeatMap(data=heatdata, x='x', y='y', values='values', title = 'SUPERHOT')

    # LEGEND
    #TODO
    """
    legend = Figure(tools=None)
    legend.toolbar_location=None
    legend.rect(x=0.5, y='value', fill_color='color', width=1, height=1, source=heatdata)
    layout = hplot(main, legend)
    """

    # CALLBACK FUNCS
    def update_data(attrib,old,new):
        g = gliders.value
        #depth   = load_sensor(g, 'm_depth')
        #celcius = load_sensor(g, 'sci_water_temp')
        t = 1000*util.time()
        ego = dict(x=[t-4*60*1000,t-3*60*1000,t-2*60*1000,t-1*60*1000],
                        y=[1,1,2,2], values=[1,2,3,4])
        fig1.pprint_props()


    #GLIDER SELECTS
    def glider_buttons(increment):
        ops = gliders.options
        new_index = ops.index(gliders.value) + increment
        if new_index >= len(ops):
            new_index = 0
        elif new_index < 0:
            new_index = len(ops)-1
        gliders.value = ops[new_index]
    def next_glider_func():
        glider_buttons(1)
    def prev_glider_func():
        glider_buttons(-1)

    gliders.on_change('value', update_data)
    next_glider.on_click(next_glider_func)
    prev_glider.on_click(prev_glider_func)

    update_data(None,None,None)

    return vplot(control_box, fig1)
开发者ID:ssb109,项目名称:WHOI_OOI_Glider_Repo,代码行数:65,代码来源:plot_heatmap.py

示例13: radio_group_handler

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
    session.store_document(document)

def radio_group_handler(active):
    print("radio_group_handler: %s" % active)
    session.store_document(document)

def checkbox_button_group_handler(active):
    print("checkbox_button_group_handler: %s" % active)
    session.store_document(document)

def radio_button_group_handler(active):
    print("radio_button_group_handler: %s" % active)
    session.store_document(document)

button = Button(label="Push button", icon=Icon(name="check"), type="primary")
button.on_click(button_handler)

toggle = Toggle(label="Toggle button", type="success")
toggle.on_click(toggle_handler)

menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3", "item_3")]
dropdown = Dropdown(label="Dropdown button", type="warning", menu=menu)
dropdown.on_click(dropdown_handler)

menu = [("Item 1", "foo"), ("Item 2", "bar"), None, ("Item 3", "baz")]
split = Dropdown(label="Split button", type="danger", menu=menu, default_action="baz")
split.on_click(split_handler)

checkbox_group = CheckboxGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_group.on_click(checkbox_group_handler)
开发者ID:CatherineH,项目名称:bokeh,代码行数:32,代码来源:buttons_server.py

示例14: Div

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]
)
cluster_stats.width = 500
cluster_stats.height = 100

cluster_commonality = Div(
    render_as_text=False,
    text=generate_display_string("")
)
cluster_commonality.width = 500
cluster_commonality.height = 300

split_button = Button(label="Split", button_type="success", width=150)
no_split_button = Button(label="Keep", button_type="success", width=150)
start_button = Button(label="Start", button_type="success", width=150)

split_button.on_click(lambda: _fit_util(1))
no_split_button.on_click(lambda: _fit_util(0))
start_button.on_click(lambda: _fit_util(2))

inputs = widgetbox(text_input, cluster_stats, cluster_commonality)

clusters = _fixed_clusters
l = layout(
    [
        [
            column(p_title, row(start_button, no_split_button, split_button), inputs),
            p
        ]
    ]
)
curdoc().add_root(l)
开发者ID:CylanceSPEAR,项目名称:NMAP-Cluster,代码行数:33,代码来源:Interactive_Clustering_bokeh.py

示例15: plot

# 需要导入模块: from bokeh.models.widgets import Button [as 别名]
# 或者: from bokeh.models.widgets.Button import on_click [as 别名]

#.........这里部分代码省略.........

        elif chnk in ['24hr', '30days']:
            chunk_ID.text = '{} \nSTART: {} \nEND:   {}'.format(g, e2ts(startend[0]), e2ts(startend[1]))
        elif chnk == '-ALL-':
            chunk_ID.text = '{} \nSTART: {} \nEND:   {}'.format(g,e2ts(depth.data['x'][0] /1000),
                                                                  e2ts(depth.data['x'][-1]/1000))


        vert_vel.data  = calc_vert_vel(depth.data)

        mbpump.data,_     = load_sensor(g, 'm_de_oil_vol', chnk, chindex)
        if len(mbpump.data['x']) > 1:
            #for yax in fig2.select('mbpump'):
            #    yax.legend = 'm_de_oil_vol'
            pass
        else:
            mbpump.data,_     = load_sensor(g, 'm_ballast_pumped', chnk, chindex)
            #for yax in fig2.select('mbpump'):
            #    yax.legend = 'm_ballast_pumped'
        battpos.data,_ = load_sensor(g, 'm_battpos',    chnk, chindex)
        pitch.data,_   = load_sensor(g, 'm_pitch',      chnk, chindex)
        pitch.data['y'] = [math.degrees(y) for y in pitch.data['y']]

        mfin.data,_     = load_sensor(g, 'm_fin',     chnk, chindex)
        cfin.data,_     = load_sensor(g, 'c_fin',     chnk, chindex)
        mroll.data,_    = load_sensor(g, 'm_roll',    chnk, chindex)
        mheading.data,_ = load_sensor(g, 'm_heading', chnk, chindex)
        cheading.data,_ = load_sensor(g, 'c_heading', chnk, chindex)
        mfin.data['y']     = [math.degrees(y) for y in mfin.data['y']]
        cfin.data['y']     = [math.degrees(y) for y in cfin.data['y']]
        mheading.data['y'] = [math.degrees(y) for y in mheading.data['y']]
        cheading.data['y'] = [math.degrees(y) for y in cheading.data['y']]
        mroll.data['y']    = [math.degrees(y) for y in mroll.data['y']]

        fig1.yaxis[1].visible = True
        fig2.yaxis[1].visible = True
        fig3.yaxis[1].visible = True


    #GLIDER SELECTS
    def glider_buttons(increment):
        ops = gliders.options
        new_index = ops.index(gliders.value) + increment
        if new_index >= len(ops):
            new_index = 0
        elif new_index < 0:
            new_index = len(ops)-1
        gliders.value = ops[new_index]
        chunkation_update(None, None, None) #reset chunk indicator and clicks
    def next_glider_func():
        glider_buttons(1)
    def prev_glider_func():
        glider_buttons(-1)
    def update_glider(attrib,old,new):
        chunk_indicator.value = '0'
        #update_data(None,None,None)


    gliders.on_change('value', update_glider)
    next_glider.on_click(next_glider_func)
    prev_glider.on_click(prev_glider_func)


        #CHUNK SELECTS
    def chunkation_update(attrib,old,new):
        chunk_indicator.value = '0'
        prev_chunk.clicks = 0
        next_chunk.clicks = 0
        update_data(None,None,None)
        if new == '-ALL-':
            chunk_indicator.value = '-'

    def chunk_func():
        chunkdiff = prev_chunk.clicks - next_chunk.clicks
        if chunkdiff < 0:
            prev_chunk.clicks = 0
            next_chunk.clicks = 0
            chunkdiff = 0
        print (chunkdiff)
        chunk_indicator.value = str(chunkdiff)

    def chunk_indicator_update(attrib,old,new):
        try:
            if abs(int(old)-int(new))>1: #manual update, triggers new non-manual indicator update, ie else clause below
                prev_chunk.clicks = int(new)
                next_chunk.clicks = 0
            else:
                update_data('chunk',int(old),int(new))
            print("UPDATE", old, new)
        except Exception as e:
            print(type(e),e, old, new)

    chunkations.on_change('value', chunkation_update)
    chunk_indicator.on_change('value', chunk_indicator_update)
    next_chunk.on_click(chunk_func)
    prev_chunk.on_click(chunk_func)

    update_data(None,None,None)

    return vplot(control_box, figs)
开发者ID:ssb109,项目名称:WHOI_OOI_Glider_Repo,代码行数:104,代码来源:plot_overview.py


注:本文中的bokeh.models.widgets.Button.on_click方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。