def add_count_toggle(plot): from bokeh.layouts import widgetbox from bokeh.models import (CustomJS, Column, Circle, Rect, ColumnDataSource, LinearColorMapper, ColorBar, Label) from bokeh.models.widgets import RadioButtonGroup args = dict( circle=None, rect=None, ) for r in plot.references(): if isinstance(r, Circle): args['circle'] = r elif isinstance(r, Rect): args['rect'] = r elif isinstance(r, LinearColorMapper): args['cmapper'] = r elif isinstance(r, ColorBar): args['cbar'] = r elif isinstance(r, ColumnDataSource): args['ds'] = r elif isinstance(r, Label): args['title'] = r callback = CustomJS(args=args, code=""" var label = cb_obj.labels[cb_obj.active]; var selection = {Observations: 'count', Subjects: 'subjects'}[label]; if (circle !== null) {circle.fill_color.field = selection}; if (rect !== null && rect.fill_color) {rect.fill_color.field = selection }; var max_val = Math.max.apply(null, ds.data[selection]); cmapper.high = max_val; cbar.ticker.ticks = [0, max_val]; split_title = title.text.split(' '); split_title[2] = label.toLowerCase(); title.text = split_title.join(' '); ds.trigger("change"); """) plot.min_border_top = 50 radio_button_group = RadioButtonGroup(labels=["Observations", "Subjects"], active=0) radio_button_group.callback = callback widgets = widgetbox(radio_button_group, width=300) return Column(widgets, plot)
) table_source.data = dict(dates=df['date'], count=df['count']) timeframe.on_change('value', lambda attr, old, new: update(attr, old, new)) # radios.on_change('active', lambda attr, old, new: update(attr, old, new)) radios.callback = CustomJS(args=dict(line0=dc_50_line, line1=dc_51_line), code=""" console.log(cb_obj.active); line0.visible = false; line1.visible = false; if (cb_obj.active == 1) { line1.visible = false; line0.visible = true; } else if (cb_obj.active == 2){ line1.visible = true; line0.visible = false; } else if (cb_obj.active == 0){ line1.visible = true; line0.visible = true; } """) # Datatable functionality table_data = dict(dates=df['date'], count=df['count']) table_source = ColumnDataSource(table_data) columns = [ TableColumn(field="dates", title="Date", formatter=DateFormatter()), TableColumn(field="count", title="Abort Count"),
color="navy") c = p1.vbar(source=source, width=0.5, bottom=0, x='poslanik1', top='np', color="#B3DE69") p1.xaxis.major_label_orientation = pi / 4 radio_button_group = RadioButtonGroup(labels=['Broj pratilaca', 'Prati', 'NP'], active=0) radio_button_group.callback = CustomJS(args=dict(bar0=a, bar1=b, bar2=c), code=""" bar0.visible = false; bar1.visible = false; bar2.visible = false; if (cb_obj.active == 0) { bar0.visible = true; } else if (cb_obj.active == 1) { bar1.visible = true; } else if (cb_obj.active == 2) { bar2.visible = true; } """) layout = column(widgetbox(radio_button_group), p1) curdoc().add_root(layout)
data: {"index": active_button}, dataType: 'json', success: function (json_from_server) { var test = json_from_server[active_button] fig.y_range.start = test[0]; fig.y_range.end = test[1]; fig.x_range.start = date_ints[active_button] fig.x_range.end = date_ints[6] }, error: function() { alert("Oh no, something went wrong. Search for an error " + "message in Flask log and browser developer tools."); } }); """ % (date_ints, stock_ticker)) p.js_on_event('tap', tap_callback) button2.js_on_event(ButtonClick, button_callback) radio_button_group.callback = radio_button_callback lay_out = column(row(text_input, button2), radio_button_group, output, row(p,div)) curdoc().add_root(lay_out) js,div=components(lay_out, INLINE) cdn_js=INLINE.render_js() cdn_css=INLINE.render_css()
# red glyphs off elif (0 not in cb_obj.active): red_glyphs[tabs.active].line_alpha = 0.0 # blue glyphs on if (1 in cb_obj.active): blue_glyphs[tabs.active].line_alpha = 0.5 # blue glyphs off elif (1 not in cb_obj.active): blue_glyphs[tabs.active].line_alpha = 0.0 # linkages coalesced_callback = CustomJS.from_py_func( fun_callback) # only convert to JS once! tabs.callback = coalesced_callback widget_object_types.callback = coalesced_callback widget_types_types.callback = coalesced_callback widget_galaxy_type.callback = coalesced_callback widget_plot_types.callback = CustomJS.from_py_func( plot_types_callback ) # this can go straight in (unlike coalesced) since only one idget calls it; it only gets instanced once # final panel building widget_group_one = widgetbox(children=[ widget_telescope_sizes, widget_object_types, widget_types_types, widget_galaxy_type ]) widget_group_two = layout([[widget_mag_input], [widget_filters, widget_mag_type]]) widget_group_three = widgetbox(children=[ widget_grating_types, widget_redshift, widget_exposure_time, widget_seeing,
error = Paragraph() calculation_time = Paragraph() total_BED = Paragraph() model_type = Paragraph() num_of_calls = Paragraph() info_data_uploaded = Paragraph() info_data_uploaded.text = default_file_BED + " loaded." rdn_btn_title = Div( text="""<font size="-0.5">Select the type of model: </font>""", width=600, height=15) in_model_rdn_btn = RadioButtonGroup( labels=["Linear", "Heuristic", "Automatic"], active=2) in_model_rdn_btn.callback = CustomJS( args=dict(radioButton=in_model_rdn_btn), code=bgui_js_handlers.in_model_rdn_btn_callback_code) in_model_rdn_btn.on_change("active", selected_model_changed) in_min_time = ColumnDataSource(data=dict(val=[MIN_LP_TIME])) in_time_slider = Slider(start=MIN_LP_TIME, end=MAX_LP_TIME, value=10, step=1, title="Set the time for calculation [hrs]") in_capacity_txt = TextInput(value="100", title="Set the capacity:") in_capacity_txt.callback = CustomJS( args={ 'min_time': in_min_time, 'time': in_time_slider, 'radioButton': in_model_rdn_btn },