def test_js_on_change_executes(self, bokeh_model_page) -> None: button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) button.js_on_event('menu_item_click', CustomJS(code=RECORD("value", "this.item"))) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(1)") item.click() results = page.results assert results == {'value': "item_1_value"} button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(3)") item.click() results = page.results assert results == {'value': "item_3_value"} button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(2)") item.click() results = page.results assert results == {'value': "item_2_value"} assert page.has_no_console_errors()
def test_displays_button_type(self, typ, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, button_type=typ, css_classes=["foo"]) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') assert typ in button.get_attribute('class')
def test_displays_button_type(self, typ, bokeh_model_page) -> None: button = Dropdown(label="Dropdown button", menu=items, button_type=typ, css_classes=["foo"]) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') assert typ in button.get_attribute('class')
def test_js_on_change_executes(self, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) button.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value"))) page = bokeh_model_page(button) button = page.driver.find_element_by_class_name('foo') button.click() item = page.driver.find_element_by_link_text("Item 1") item.click() results = page.results assert results == {'value': "item_1_value"} button = page.driver.find_element_by_class_name('foo') button.click() item = page.driver.find_element_by_link_text("Item 3") item.click() results = page.results assert results == {'value': "item_3_value"} button = page.driver.find_element_by_class_name('foo') button.click() item = page.driver.find_element_by_link_text("Item 2") item.click() results = page.results assert results == {'value': "item_2_value"} assert page.has_no_console_errors()
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 = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) def cb(event): item = event.item if item == "item_1_value": source.data = dict(x=[10, 20], y=[10, 10]) elif item == "item_2_value": source.data = dict(x=[100, 200], y=[100, 100]) elif item == "item_3_value": source.data = dict(x=[1000, 2000], y=[1000, 1000]) button.on_event('menu_item_click', cb) doc.add_root(column(button, plot))
def setup_widgets(self): """ Critical widgets for interactive data management. """ self.update_pusher = Button(label="Push", button_type="success", height_policy="fit", width_policy="min") self.data_committer = Dropdown( label="Commit", button_type="warning", menu=[ *self.__class__.PUBLIC_SUBSETS, *self.__class__.PRIVATE_SUBSETS ], height_policy="fit", width_policy="min", ) self.dedup_trigger = Button( label="Dedup", button_type="warning", height_policy="fit", width_policy="min", ) def commit_base_callback(): """ COMMIT creates cross-duplicates between subsets. - PUSH shall be blocked until DEDUP is executed. """ self.dedup_trigger.disabled = False self.update_pusher.disabled = True def dedup_base_callback(): """ DEDUP re-creates dfs with different indices than before. - COMMIT shall be blocked until PUSH is executed. """ self.update_pusher.disabled = False self.data_committer.disabled = True self.df_deduplicate() def push_base_callback(): """ PUSH enforces df consistency with all linked explorers. - DEDUP could be blocked because it stays trivial until COMMIT is executed. """ self.data_committer.disabled = False self.dedup_trigger.disabled = True self.update_pusher.on_click(push_base_callback) self.data_committer.on_click(commit_base_callback) self.dedup_trigger.on_click(dedup_base_callback) self.help_div = dataset_help_widget()
def make_dropdown(prop, menu): dropdown = Dropdown(label=prop, menu=menu) cb = CustomJS(args=dict(lines=lines, prop=prop), code=""" for (var i = 0; i < lines.length; i++) { const glyph = lines[i].glyph; glyph[prop] = cb_obj.item; } """) dropdown.js_on_click(cb) return dropdown
def test_js_on_change_executes(self, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) button.js_on_event('menu_item_click', CustomJS(code=RECORD("value", "this.item"))) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(1)") item.click() results = page.results assert results == {'value': "item_1_value"} button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(3)") item.click() results = page.results assert results == {'value': "item_3_value"} button = page.driver.find_element_by_css_selector('.foo button') button.click() item = page.driver.find_element_by_css_selector(".foo .bk-menu > *:nth-child(2)") item.click() results = page.results assert results == {'value': "item_2_value"} assert page.has_no_console_errors()
def test_displays_button_type(self, typ, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, button_type=typ, css_classes=["foo"]) page = bokeh_model_page(button) button_div = page.driver.find_element_by_class_name('foo') button = button_div.find_element_by_tag_name("button") assert typ in button.get_attribute('class')
def test_displays_menu_items(self, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') assert button.text == "Dropdown button" button.click() menu = page.driver.find_element_by_css_selector('.foo .bk-menu') assert menu.is_displayed()
def test_displays_menu_items(self, bokeh_model_page) -> None: button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) page = bokeh_model_page(button) button = page.driver.find_element_by_css_selector('.foo button') assert button.text == "Dropdown button" button.click() menu = page.driver.find_element_by_css_selector('.foo .bk-menu') assert menu.is_displayed()
class ReferenceWidget: "Dropdown for choosing the reference" __files: FileList __theme: ReferenceWidgetTheme __widget: Dropdown def __init__(self, ctrl, model) -> None: self.__theme = ctrl.theme.swapmodels(ReferenceWidgetTheme()) self.__model = model self.__files = FileList(ctrl) def addtodoc(self, mainview, ctrl, *_) -> List[Widget]: "creates the widget" self.__widget = Dropdown(name='HS:reference', width=self.__theme.width, height=self.__theme.height, **self.__data()) @mainview.actionifactive(ctrl) def _py_cb(new): inew = int(new.item) val = None if inew < 0 else [i for _, i in self.__files()][inew] self.__model.fittoreference.reference = val def _observe(old=None, **_): if 'reference' in old and mainview.isactive(): data = self.__data() mainview.calllater(lambda: self.__widget.update(**data)) ctrl.display.observe(FitToReferenceStore().name, _observe) self.__widget.on_click(_py_cb) return [self.__widget] def reset(self, resets): "updates the widget" resets[self.__widget].update(**self.__data()) @property def widget(self): "returns the widget" return self.__widget def __data(self) -> dict: lst = list(self.__files()) menu: list = [(j, str(i)) for i, j in enumerate(i for i, _ in lst)] menu += [None, (self.__theme.title, '-1')] key = self.__model.fittoreference.reference index = -1 if key is None else [i for _, i in lst].index(key) return dict(menu=menu, label=menu[index][0], value=str(index))
def addtodoc(self, mainview, ctrl, *_) -> List[Widget]: "creates the widget" self._widget = Dropdown(name='Cycles:Sequence', width=self._theme.width, height=self._theme.height, **self._data()) mainview.differedobserver(self._data, self._widget, ctrl.theme, self._model.sequencemodel.config, ctrl.display, self._model.sequencemodel.display) self._widget.on_click(ctrl.action(self._onclick)) return [self._widget]
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 = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) def cb(event): item = event.item if item == "item_1_value": source.data = dict(x=[10, 20], y=[10, 10]) elif item == "item_2_value": source.data = dict(x=[100, 200], y=[100, 100]) elif item == "item_3_value": source.data = dict(x=[1000, 2000], y=[1000, 1000]) button.on_event('menu_item_click', cb) doc.add_root(column(button, plot))
def test_displays_button_type(self, typ, bokeh_model_page: BokehModelPage) -> None: button = Dropdown(label="Dropdown button", menu=items, button_type=typ) page = bokeh_model_page(button) button_el = find_element_for(page.driver, button, "button") assert typ in button_el.get_attribute('class')
def test_displays_menu_items(self, bokeh_model_page): button = Dropdown(label="Dropdown button", menu=items, css_classes=["foo"]) page = bokeh_model_page(button) button_div = page.driver.find_element_by_class_name('foo') button = button_div.find_element_by_tag_name("button") assert button.text == "Dropdown button" button.click() links = page.driver.find_elements_by_css_selector('ul li a') assert len(links) == 3 for i, link in enumerate(links): assert link.text == items[i][0] assert link.get_attribute('data-value') == items[i][1]
def __init__(self): self.rubric = pd.read_excel( os.path.join(file_path, "data/Rubric.xlsx"), "Rubric v3") self.tool_list = self.rubric.drop( ["Category", "Criteria", "Grading Scale", "Definition"], axis=1).columns self.tool_dir = os.listdir(os.path.join(file_path, "static/images")) self.select_tool = Dropdown(menu=list( zip(self.tool_list, self.tool_list)), label="Choose Tool", button_type="primary") self.select_tool.on_change("value", self.select_callback) self.app_layout = layout(self.select_tool)
def _init_controls(self): if not self.file_name: return collection_menu = [ self._collection_menu_item(row) for row in self.collections.iterrows() ] probe_menu = [ self._probe_menu_item(row) for row in self.probes.iterrows() ] stats_menu = [('mean', 'mean'), ('median', 'median'), ('min', 'min'), ('max', 'max'), ('count', 'count'), None, ('ter', 'ter')] num_grid_cells = self.grid_dims[0] * self.grid_dims[1] self.collection_controls = np.array([ (Dropdown(label='Collection', button_type='warning', menu=collection_menu) if i % 2 == 0 else None) for i in range(num_grid_cells) ]).reshape(*self.grid_dims) self.probe_controls = np.array([ Dropdown(label='Probe', button_type='warning', menu=probe_menu) for i in range(num_grid_cells) ]).reshape(*self.grid_dims) self.stat_controls = np.array([ Dropdown(label='Stat', button_type='warning', menu=stats_menu) for i in range(num_grid_cells) ]).reshape(*self.grid_dims) controls = [ self.collection_controls, self.probe_controls, self.stat_controls ] all_controls = [] for row in range(self.grid_dims[0]): for col in range(self.grid_dims[1]): for c in controls: all_controls.append(c[row, col]) if c[row, col] is None: continue c[row, col].on_change('value', lambda attr, old, new, row=row, col= col: self._update(row, col)) self.grid_controls = np.array(all_controls).reshape( *self.grid_dims, len(controls))
def setup_file_export(self): self.file_exporter = Dropdown( label="Export", button_type="warning", menu=["Excel", "CSV", "JSON", "pickle"], height_policy="fit", width_policy="min", ) def callback_export(event, path_root=None): """ A callback on clicking the 'self.annotator_export' button. Saves the dataframe to a pickle. """ export_format = event.item # auto-determine the export path root if path_root is None: timestamp = current_time("%Y%m%d%H%M%S") path_root = f"hover-dataset-export-{timestamp}" export_df = self.to_pandas(use_df=True) if export_format == "Excel": export_path = f"{path_root}.xlsx" export_df.to_excel(export_path, index=False) elif export_format == "CSV": export_path = f"{path_root}.csv" export_df.to_csv(export_path, index=False) elif export_format == "JSON": export_path = f"{path_root}.json" export_df.to_json(export_path, orient="records") elif export_format == "pickle": export_path = f"{path_root}.pkl" export_df.to_pickle(export_path) else: raise ValueError(f"Unexpected export format {export_format}") self._good(f"Saved DataFrame to {export_path}") # assign the callback, keeping its reference self._callback_export = callback_export self.file_exporter.on_click(self._callback_export)
def test_displays_menu_items(self, bokeh_model_page: BokehModelPage) -> None: button = Dropdown(label="Dropdown button", menu=items) page = bokeh_model_page(button) button_el = find_element_for(page.driver, button, "button") assert button_el.text == "Dropdown button" button_el.click() menu = find_element_for(page.driver, button, ".bk-menu") assert menu.is_displayed()
def auxiliary_apps_dropdown(self): """Return a button that opens statistics application. """ js_code = """ switch (this.item) { case "Statistics": window.open('/statistics'); break; case "Hitrate": window.open('/hitrate'); break; case "ROI Intensities": window.open('/roi_intensities'); break; case "ROI Pump-Probe": window.open('/roi_pump_probe'); break; case "ROI Projections": window.open('/roi_projections'); break; case "Radial Profile": window.open('/radial_profile'); break; } """ auxiliary_apps_dropdown = Dropdown( label="Open Auxiliary App", menu=[ "Statistics", "Hitrate", "ROI Intensities", "ROI Pump-Probe", "ROI Projections", "Radial Profile", ], default_size=145, ) auxiliary_apps_dropdown.js_on_click(CustomJS(code=js_code)) return auxiliary_apps_dropdown
def test_js_on_change_executes(self, bokeh_model_page: BokehModelPage) -> None: button = Dropdown(label="Dropdown button", menu=items) button.js_on_event('menu_item_click', CustomJS(code=RECORD("value", "this.item"))) page = bokeh_model_page(button) button_el = find_element_for(page.driver, button, "button") button_el.click() item = find_element_for(page.driver, button, ".bk-menu > *:nth-child(1)") item.click() results = page.results assert results == {'value': "item_1_value"} button_el = find_element_for(page.driver, button, "button") button_el.click() item = find_element_for(page.driver, button, ".bk-menu > *:nth-child(3)") item.click() results = page.results assert results == {'value': "item_3_value"} button_el = find_element_for(page.driver, button, "button") button_el.click() item = find_element_for(page.driver, button, ".bk-menu > *:nth-child(2)") item.click() results = page.results assert results == {'value': "item_2_value"} assert page.has_no_console_errors()
def addtodoc(self, mainview, ctrl, *_) -> List[Widget]: "creates the widget" self.__widget = Dropdown(name='HS:reference', width=self.__theme.width, height=self.__theme.height, **self.__data()) @mainview.actionifactive(ctrl) def _py_cb(new): inew = int(new.item) val = None if inew < 0 else [i for _, i in self.__files()][inew] self.__model.fittoreference.reference = val def _observe(old=None, **_): if 'reference' in old and mainview.isactive(): data = self.__data() mainview.calllater(lambda: self.__widget.update(**data)) ctrl.display.observe(FitToReferenceStore().name, _observe) self.__widget.on_click(_py_cb) return [self.__widget]
def scatterSelect(): colormap = {'0': 'red', '1': 'green', 'virginica': 'blue'} a=[1,2,3,4,5,6,7,8,9] b=[2,3,4,5,6,7,8,9,10] c=[2,5,6,8,9,7,2,2,4] d=['red','green','green','blue','red','green','green','blue','green'] source=ColumnDataSource(data={'a':a,'b':b,'c':c,'d':d,'x':a,'y':b,'color':d}) p=figure(title = "x-y", sizing_mode="fixed", plot_width=600, plot_height=400,tools='pan,wheel_zoom,box_zoom,save,reset') p.toolbar.logo=None p.add_tools( HoverTool( show_arrow=True, line_policy='next', tooltips=[ ('X_value', '$data_x'), ('Y_value', '$data_y') ] ) ) p.scatter(x='x',y='y', color='color',source=source) from bokeh.layouts import column,row from bokeh.models import Dropdown callback1 = CustomJS(args=dict(source=source,axis=p.xaxis[0]), code=""" var data = source.data; var f = cb_obj.value data['x']=data[f] axis.axis_label=f source.change.emit(); """) callback2 = CustomJS(args=dict(source=source,axis=p.yaxis[0]), code=""" var data = source.data; var f = cb_obj.value data['y']=data[f] axis.axis_label=f source.change.emit(); """) dp1 = Dropdown(label="X value",menu=[('aa','a'),('bb','b'),('cc','c')],default_value='b') dp1.js_on_change('value', callback1) dp2 = Dropdown(label="Y value",menu=['a','b','c'],default_value='b') dp2.js_on_change('value', callback2) layout = column(row(dp1,dp2), p) return json.dumps(json_item(layout))
def rank_criteria(self): for c in sorted(self.chosen_criteria): self.ranking.update({ c: [ PreText(text="Scenario {}".format( sorted(self.criteria).index(c) + 1)), Dropdown(menu=[ (str(i), str(i)) for i in range(1, len(self.chosen_criteria) + 1) ], button_type="primary", label="Rank") ] }) for k in self.ranking.keys(): self.ranking[k][1].on_change( "value", partial(self.ranking_label_callback, k=k))
def __init__(self): self.plot = bokeh.plotting.figure( plot_width=500, plot_height=500, x_range=Range1d(0, 1, bounds=(-0.25, 1.25)), y_range=Range1d(0, 1, bounds=(-0.25, 1.25)), ) self.plot.tools.pop(-1) # remove help tool self.plot.tools.pop(-2) # remove save tool self.plot.toolbar.active_scroll = self.plot.tools[ 1] # activate wheel scroll self.plot.toolbar.logo = None self.plot.xaxis.visible = False self.plot.yaxis.visible = False self.plot.xgrid.grid_line_color = None self.plot.ygrid.grid_line_color = None self.plot.outline_line_alpha = 0 menu = [] self.imgSelectDropDown: Dropdown = Dropdown(label="SelectImage", button_type="warning", menu=menu) self.widget = Panel(child=Row(self.plot, self.imgSelectDropDown), title='Images')
# copy list to make it later possible to delete/ add items for the list without using original list (NOT YET USED) show_figures = figures splom = gridplot(show_figures, ncols=3, toolbar_location='right') p4 = gridplot([[splom, dum_fig]], toolbar_location=None) # [END] tab 4 - splom plot -------------------------------------------------------------------------------------------- # // TOOL GUI =========================================================================================================================================================== # Spinner GUI spinner = Spinner(title="Size", low=0, high=4, step=0.1, value=1, width=300) # spinner.js_link('value', points.glyph, 'radius') # Dropdown menu GUI menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3", "item_3")] dropdown = Dropdown(label="Dropdown button", button_type="warning", menu=menu) dropdown.js_on_event( "menu_item_click", CustomJS(code="console.log('dropdown: ' + this.item, this.toString())")) # Toggle button GUI toggle = Toggle(label="Button", button_type="success") toggle.js_on_click( CustomJS(code=""" console.log('toggle: active=' + this.active, this.toString()) """)) # choice menu GUI OPTIONS = [str(i) for i in range(20)] multi_choice = MultiChoice(value=["foo", "baz"], options=OPTIONS) multi_choice.js_on_change(
bar_chart420.visible = False bar_chart330.visible = False elif new == '2e Klass': bar_chart.visible = False bar_chart1.visible = False bar_chart420.visible = True bar_chart330.visible = False elif new == '3e Klass': bar_chart.visible = False bar_chart1.visible = False bar_chart420.visible = False bar_chart330.visible = True # Create a dropdown Select widget: select selectRegio = Dropdown(label="Maak keuze uit de klasse", menu=["All", "1e Klass", "2e Klass", "3e Klass"]) # Attach the update_plot callback to the 'value' property of select selectRegio.on_click(update_bar_chart) # Hoofdstuk 3 Scatter en 2-D visualisatie titel4 = Div(text="<h2"">Hoofdstuk 3: Scatterplots en 2-D visualisaties""</h2>", width=800, height=50) text4 = Div(text="<h4"">Hieronder volgt scatterplot van prijs per ticket tegenover de GDP per capita""</h4>", width=800, height=50) # dataframes FareVsGDP = pd.read_csv('Data K\FareVsGDP.csv') FareVsGDP1 = pd.read_csv('Data K\FareVsGDP1eKlass.csv') FareVsGDP2 = pd.read_csv('Data K\FareVsGDP2eKlass.csv') FareVsGDP3 = pd.read_csv('Data K\FareVsGDP3eKlass.csv') # dropdown
source=source_critical_lines, color='red', legend='critical lines') # initialize controls # text input for input of the ode system [u,v] = [x',y'] u_input = TextInput(value=odesystem_settings.sample_system_functions[ odesystem_settings.init_fun_key][0], title="u(x,y):") v_input = TextInput(value=odesystem_settings.sample_system_functions[ odesystem_settings.init_fun_key][1], title="v(x,y):") # dropdown menu for selecting one of the sample functions sample_fun_input = Dropdown( label="choose a sample function pair or enter one below", menu=odesystem_settings.sample_system_names) # Interactor for entering starting point of initial condition interactor = my_bokeh_utils.Interactor(plot) # initialize callback behaviour sample_fun_input.on_click(sample_fun_change) u_input.on_change('value', ode_change) v_input.on_change('value', ode_change) interactor.on_click(initial_value_change) # calculate data init_data() # lists all the controls in our app associated with the default_funs panel
# initialize data source source_function1 = ColumnDataSource(data=dict(x=[], y=[])) source_function2 = ColumnDataSource(data=dict(x=[], y=[])) source_result = ColumnDataSource(data=dict(x=[], y=[])) source_convolution = ColumnDataSource(data=dict(x=[], y=[])) source_xmarker = ColumnDataSource(data=dict(x=[], y=[])) source_overlay = ColumnDataSource(data=dict(x=[], y=[], y_neg=[], y_pos=[])) # initialize properties update_is_enabled = True # initialize controls # dropdown menu for sample functions function_type = Dropdown(label="choose a sample function pair or enter one below", menu=convolution_settings.sample_function_names) function_type.on_click(function_pair_input_change) # slider controlling the evaluated x value of the convolved function x_value_input = Slider(title="x value", name='x value', value=convolution_settings.x_value_init, start=convolution_settings.x_value_min, end=convolution_settings.x_value_max, step=convolution_settings.x_value_step) x_value_input.on_change('value', input_change) # text input for the first function to be convolved function1_input = TextInput(value=convolution_settings.function1_input_init, title="my first function:") function1_input.on_change('value', input_change) # text input for the second function to be convolved function2_input = TextInput(value=convolution_settings.function1_input_init, title="my second function:") function2_input.on_change('value', input_change) # initialize plot
from bokeh.models import Button, DataTable, Dropdown, PreText, RadioButtonGroup from bokeh.layouts import layout from bokeh.plotting import curdoc from file_input import ImportData imp_data = ImportData() button = Button(label="Upload", button_type="success") button.js_on_click(imp_data.cb) imp_data.x_label = PreText(text="x axis variable") imp_data.y_label = PreText(text="y axis variable") imp_data.g_label = PreText(text="group variable") imp_data.x_drop = Dropdown(label="x-axis Variable") imp_data.y_drop = Dropdown(label="y-axis Variable") imp_data.g_drop = Dropdown(label="Group Variable") imp_data.dt = DataTable() imp_data.plot_type = RadioButtonGroup(labels=["Line", "Bar", "Scatter", "Histogram"]) imp_data.plot_label = PreText(text="Plot type") imp_data.submit = Button(label="Submit", button_type="success") app_layout = layout([button]) doc = curdoc() imp_data.layout = app_layout imp_data.doc = doc doc.add_root(app_layout)
tty = [(dict['y3'], '@{' + dict['y3'] + '}')] ttr = [(dict['r3'], '@{' + dict['r3'] + '}')] ttc = [(dict['c3'], '@{' + dict['c3'] + '}')] plot3.tools[6] = HoverTool( tooltips=[("index", "$index"), ("Country", "@Country")] + ttx + tty + ttr + ttc) ttx = [(dict['x4'], '@{' + dict['x4'] + '}')] tty = [(dict['y4'], '@{' + dict['y4'] + '}')] ttr = [(dict['r4'], '@{' + dict['r4'] + '}')] ttc = [(dict['c4'], '@{' + dict['c4'] + '}')] plot4.tools[6] = HoverTool( tooltips=[("index", "$index"), ("Country", "@Country")] + ttx + tty + ttr + ttc) dropdownX1 = Dropdown(label="X value1", button_type="default", menu=menu) dropdownX2 = Dropdown(label="X value2", button_type="default", menu=menu) dropdownX3 = Dropdown(label="X value3", button_type="default", menu=menu) dropdownX4 = Dropdown(label="X value4", button_type="default", menu=menu) def dropdownX_handler1(new): dictionary['xdata1'] = dictionary[new.item] dict['x1'] = new.item ds1.data = dictionary plot1.xaxis.axis_label = new.item update_tooltip() def dropdownX_handler2(new): dictionary['xdata2'] = dictionary[new.item]
wbox = widget # create min / max TextInput widgets for updating the value range update_figs(None, None, None) # create the results figure object fig = figure(toolbar_location='above', tools='pan,reset,save', logo='grey', width=700, height=250) # create the x-var dropdown menu xmenu = [] for param in r0.keys(): for item in r0[param]: xmenu.append((item, item)) xmenu.append(None) xdrop = Dropdown(menu=xmenu[:-1], button_type='primary') xdrop.on_change('value', update_xdrop) # create the Panel and Tabs objects for setting up the investment parameters panels = [] for param in r0.keys(): panels.append(create_panel(param, r0[param])) tabs = Tabs(tabs=panels, width=1000) # create the app layout top = row(fig, widgetbox(xdrop, width=300)) layout = column(top, tabs) # update the document and initialize the app by setting the Dropdown value curdoc().add_root(layout) param0 = list(r0.keys())[0]
"console.log('toggle(inactive): active=' + 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): 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: click ' + this.toString())")) dropdown.js_on_event( "menu_item_click", CustomJS(code="console.log('dropdown: ' + this.item, 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): click ' + this.toString())")) dropdown_disabled.js_on_event( "menu_item_click",
x = linspace(-2 * pi, 2 * pi, 1000) source = ColumnDataSource(data=dict( x=x, y1=sin(x), y2=cos(x), y3=tan(x), y4=sin(x) * cos(x), )) slider_1 = Slider(start=0, end=10, value=1, step=1, title="Stuff1") slider_2 = Slider(start=0, end=10, value=1, step=1, title="Stuff2") slider_3 = Slider(start=0, end=10, value=1, step=1, title="Stuff2") slider_4 = Slider(start=0, end=10, value=1, step=1, title="Stuff2") menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3", "item_3")] dropdown = Dropdown(label="Dropdown button", menu=menu) msg = "Returns a tuple (plot, [obj1...objN]); the former can be added to a GridPlot, and the latter is added to the plotcontext." button_1 = Button(label=msg) button_2 = Button(label=msg) button_3 = Button(label=msg) button_4 = Button(label=msg) doc = Document() def add_axes(plot, below_axis=True, left_axis=True, right_axis=False, above_axis=False): if above_axis: plot.add_layout(LinearAxis(), 'above')
timestep_slider = Slider(title="Timestep", start=CACHE.graph_attr.min_timestep, end=CACHE.graph_attr.timesteps, value=CACHE.plot.timestep, step=1, **STATIC.widget.slider) timestep_slider.on_change('value_throttled', VisualizerHandler.timestep_callback) CACHE.widgets.timestep_slider = timestep_slider # ------------------ Layouts widgets ------------------- # layout_title = h1("Layout settings") layout_algo_dropdown = Dropdown(label="Layout algorithm", menu=from_dict_to_menu(layouts.AVAILABLE)) layout_algo_dropdown.on_event('menu_item_click', VisualizerHandler.layout_algo_callback) CACHE.widgets.layout_algo_dropdown = layout_algo_dropdown # ------------------ Edges widgets ------------------- # edges_title = h1("Edges settings") thickness_slider = Slider(title="Edge thickness", start=.05, end=5, value=CACHE.plot.network.edges.thickness, step=.05, **STATIC.widget.slider) thickness_slider.on_change('value_throttled',
dict["timestamp_"+attr] = [] dict[attr] = [] # The data sources for the main plot and the task boxes source = ColumnDataSource(dict) task_source = ColumnDataSource({"tasks" : [], "time" : []}) # The data source for the plo displaying the active tasks over time session_source = ColumnDataSource({"xss": [], "yss": [], "colors": [], "tasktype": [], "running_tasks": []}) source.data, task_source.data, session_source.data = query_events(current_run) # a dropdown menu to select a run for which data shall be visualized run_menu = [(run_format(k, v['numLogEntries'], v['tstart']), add_prefix(k)) for k, v in run_map.iteritems() if v['tstart'] is not None] # use None for separator dropdown = Dropdown(label="run", button_type="warning", menu=run_menu) dropdown.on_click(lambda newValue: select_run(rem_prefix(newValue))) manualLegendBox = Div(text=legendFormat(task_types), width=PLOT_WIDTH, height=80) # info boxes to display the number of log messages in this run and the elapsed wall clock time numMessages = Div(text=infoBoxFormat("Messages", 0), width=200, height=100) runID = Div(text=infoBoxFormat("run", str(current_run)), width=400, height=100) startTime = Div(text=infoBoxFormat("start time [ms]", str(general_info["start_time"])), width=200, height=100) # Set the properties of the first plot p = figure(plot_height=PLOT_HEIGHT, plot_width=PLOT_WIDTH, #tools="pan,xpan,wheel_zoom,xwheel_zoom,ywheel_zoom,xbox_zoom,reset", tools="xpan,xwheel_zoom,xbox_zoom,reset,save", toolbar_location="above", x_axis_type="linear", y_axis_location="right", y_axis_type=None,
quiver = my_bokeh_utils.Quiver(plot) # Plot initial values plot.scatter('x0', 'y0', source=source_initialvalue, color='black', legend='(x0,y0)') # Plot streamline plot.line('x', 'y', source=source_streamline, color='black', legend='streamline') # Plot critical points and lines plot.scatter('x', 'y', source=source_critical_pts, color='red', legend='critical pts') plot.multi_line('x_ls', 'y_ls', source=source_critical_lines, color='red', legend='critical lines') # initialize controls # text input for input of the ode system [u,v] = [x',y'] u_input = TextInput(value=odesystem_settings.sample_system_functions[odesystem_settings.init_fun_key][0], title="u(x,y):") v_input = TextInput(value=odesystem_settings.sample_system_functions[odesystem_settings.init_fun_key][1], title="v(x,y):") # dropdown menu for selecting one of the sample functions sample_fun_input = Dropdown(label="choose a sample function pair or enter one below", menu=odesystem_settings.sample_system_names) # Interactor for entering starting point of initial condition interactor = my_bokeh_utils.Interactor(plot) # initialize callback behaviour sample_fun_input.on_click(sample_fun_change) u_input.on_change('value', ode_change) v_input.on_change('value', ode_change) interactor.on_click(initial_value_change) # calculate data init_data() # lists all the controls in our app associated with the default_funs panel function_controls = widgetbox(sample_fun_input, u_input, v_input,width=400)
""" return ColumnDataSource(data={'x': [], 'y': []}) # create the results figure object fig = figure(toolbar_location='above', tools='save,hover', logo='grey', width=600, height=300) fig.line('x', 'y', source=empty_data(), line_width=4) # create the x-var dropdown menu xmenu = [] for param in r0.keys(): for item in r0[param]: xmenu.append((item, item)) xmenu.append(None) xdrop = Dropdown(menu=xmenu[:-1], button_type='primary') xtext = Div(text='<center><strong>select x-var</strong></center>') # create the y-var dropdown menu ymenu = list(get_investment_results(r0).keys()) ymenu = [y for y in ymenu if 'div' not in y] ydrop = Dropdown(menu=[(x, x) for x in ymenu], button_type='primary') ytext = Div(text='<center><strong>select y-var</strong></center>') # create column layouts (panels) for setting up the investment parameters panels = [] for param in r0.keys(): panels.append(create_panel(param, r0[param])) # create div objects for investment result tables div_total_invested_capital = Div()