def init(): output_notebook() display(Javascript(_init_js)) but = '<img src="resources/show.png" width="34" height="25" style="display: inline" alt="Slideshow button" title="Enter/Exit RISE Slideshow">' txt = Div(text='<h2>You can now start the slideshow!</h3>' + f'<h3 style="margin: 0.5em 0;">Just click the RISE slideshow button above - the one that looks like: {but}<br/>' + '(or you can press alt+R on your keyboard instead if you prefer).</h3>') clearbutton = Button(label="Clear") clearbutton.js_on_click(CustomJS(code='primes_clear();')) cleartext = Paragraph(text='Clear all plots and outputs (e.g. before restarting slideshow).') increm = Toggle(label='Incremental', active=True) increm.js_on_click(CustomJS(code='primes_incremental(cb_obj.active)')) incremtext = Paragraph(text='Update timing plots incrementally (disable for static slide show).') repeats = Slider(start=1, end=10, value=3) repeats.js_on_change('value', CustomJS(code='primes_repeats(cb_obj.value)')) repeatstext = Paragraph(text='Repeats for timing measurements (higher is more accurate, but slower).') controls = layout([[clearbutton, cleartext], [increm, incremtext], [repeats, repeatstext]]) show(column(txt, controls, sizing_mode='stretch_width'))
button.on_click(lambda: print('button: click')) button.js_on_click( CustomJS(code="console.log('button: click', this.toString())")) button_disabled = Button(label="Button (disabled) - no click event", button_type="primary", disabled=True) button_disabled.on_click(lambda: print('button_disabled: click')) button_disabled.js_on_click( CustomJS(code="console.log('button_disabled: click', this.toString())")) toggle_inactive = Toggle(label="Toggle button (initially inactive)", button_type="success") toggle_inactive.on_click(lambda value: print('toggle_inactive: %s' % value)) toggle_inactive.js_on_click( CustomJS( code="console.log('toggle_inactive: ' + this.active, this.toString())") ) toggle_active = Toggle(label="Toggle button (initially active)", button_type="success", active=True) toggle_active.on_click(lambda value: print('toggle_active: %s' % value)) toggle_active.js_on_click( CustomJS( code="console.log('toggle_active: ' + this.active, this.toString())")) menu = [("Item 1", "item_1_value"), ("Item 2", "item_2_value"), None, ("Item 3", "item_3_value")] dropdown = Dropdown(label="Dropdown button", button_type="warning", menu=menu) dropdown.on_click(lambda value: print('dropdown: %s' % value))
} async function run() { var len = slider.value; var loopcount=0; while (cb_obj.active){ if (len>=endlen){ loopcount++; if(loopcount==2){ cb_obj.active=false; break; } len=minlen; } len = len+864000000; slider.value = len; await sleep(4) } } run(); ''') #loops through slider twice (only looks like once if starting at the end) #adds 10 days at a time #sleeps 4 milliseconds inbetween each increment button = Toggle(label='▶\uFE0E', button_type='success') #\uFE0E forces non emoji rendering (only on some browsers) button.js_on_click(loopchange) arrangement = layout([slider, button], tabs) show(arrangement)
from bokeh.embed import file_html from bokeh.resources import INLINE from bokeh.models import CustomJS, WidgetBox from bokeh.models.widgets import ( Button, Toggle, Dropdown, CheckboxGroup, RadioGroup, CheckboxButtonGroup, RadioButtonGroup, ) button = Button(label="Button (enabled) - has click event", button_type="primary") button.js_on_click(CustomJS(code="console.log('button: click', this.toString())")) button_disabled = Button(label="Button (disabled) - no click event", button_type="primary", disabled=True) button_disabled.js_on_click(CustomJS(code="console.log('button_disabled: click', this.toString())")) toggle_inactive = Toggle(label="Toggle button (initially inactive)", button_type="success") toggle_inactive.js_on_click(CustomJS(code="console.log('toggle_inactive: ' + this.active, this.toString())")) toggle_active = Toggle(label="Toggle button (initially active)", button_type="success", active=True) toggle_active.js_on_click(CustomJS(code="console.log('toggle_active: ' + this.active, this.toString())")) menu = [("Item 1", "item_1_value"), ("Item 2", "item_2_value"), None, ("Item 3", "item_3_value")] dropdown = Dropdown(label="Dropdown button", button_type="warning", menu=menu) dropdown.js_on_click(CustomJS(code="console.log('dropdown: ' + this.value, this.toString())")) dropdown_disabled = Dropdown(label="Dropdown button (disabled)", button_type="warning", disabled=True, menu=menu) dropdown_disabled.js_on_click(CustomJS(code="console.log('dropdown_disabled: ' + this.value, this.toString())")) #dropdown_split = Dropdown(label="Split button", button_type="danger", menu=menu, default_value="default") #dropdown_split.js_on_click(CustomJS(code="console.log('dropdown_split: ' + this.value, this.toString())"))
source3.data['x'] = orig3.data['x'] source3.data['y'] = orig3.data['y'] source4.data['x'] = orig4.data['x'] source4.data['y'] = orig4.data['y'] } // Transmit changes to the column data sources source1.change.emit(); source2.change.emit(); source3.change.emit(); source4.change.emit(); """) # Connect buttons to callback function b1.js_on_click(callback) b2.js_on_click(callback) b3.js_on_click(callback) b4.js_on_click(callback) # Create plot grid l = layout(widgetbox(row([b1,b2,b3,b4]),sizing_mode='stretch_width'),[fig_lc], sizing_mode='scale_both') # Use "show" to generate HTML file and launch plot in the browser show(l)