def __init__(self, addr=None, interval=1000.00, loop=None): if addr is None: scheduler = default_executor().scheduler if isinstance(scheduler, rpc): addr = (scheduler.ip, 9786) elif isinstance(scheduler, Scheduler): addr = ('127.0.0.1', scheduler.services['http'].port) self.addr = addr self.interval = interval self.display_notebook = False if is_kernel() and not curstate().notebook: output_notebook() assert curstate().notebook self.task_source, self.task_table = task_table_plot() self.worker_source, self.worker_table = worker_table_plot() self.output = vplot(self.worker_table, self.task_table) self.client = AsyncHTTPClient() self.loop = loop or IOLoop.current() self.loop.add_callback(self.update) self._pc = PeriodicCallback(self.update, self.interval, io_loop=self.loop) self._pc.start()
def handle_on_msg(self, _, content, buffers): """ Handler for click (and potentially other) events from the user. """ if content == "home": self.backward.append(None) self.forward = [] self.generate_content() elif content == "back": self.forward.append(self.backward.pop()) self.generate_content(self.backward[-1]) elif content == "forward": self.backward.append(self.forward.pop()) self.generate_content(self.backward[-1]) elif content == "init_complete": comms_target = self.bokeh_comms_target # TODO: Simplify this: self.bokeh_table_handle = (bokeh_io. _CommsHandle(bokeh_util.notebook. get_comms(comms_target), bokeh_io.curstate(). document, bokeh_io.curstate(). document.to_json())) bokeh_io._state.last_comms_handle = self.bokeh_table_handle else: clicked_fun = self.id_dict[content] self.backward.append(clicked_fun) self.forward = [] self.generate_content(clicked_fun)
def __init__(self, addr=None, interval=1.00): if addr is None: scheduler = default_executor().scheduler if isinstance(scheduler, rpc): addr = (scheduler.ip, scheduler.port) elif isinstance(scheduler, Scheduler): addr = ('127.0.0.1', scheduler.port) self.cds = ColumnDataSource({k: [] for k in ['host', 'cpu', 'memory', 'zero', 'left', 'mid', 'right']}) self.display_notebook = False self.figure = figure(height=200, width=800, y_range=(0, 100)) self.figure.logo = None cpu = self.figure.quad(legend='cpu', left='left', right='mid', bottom='zero', top='cpu', source=self.cds, color=(0, 0, 255, 0.5)) memory = self.figure.quad(legend='memory', left='mid', right='right', bottom='zero', top='memory', source=self.cds, color=(255, 0, 0, 0.5)) self.figure.add_tools(HoverTool(renderers=[cpu, memory], tooltips=[("host", "@host"), ("cpu", "@cpu"), ("memory", "@memory")])) self.future = self.update(addr, interval) if is_kernel() and not curstate().notebook: output_notebook() assert curstate().notebook
def __init__(self, addr=None, interval=1.00): if addr is None: scheduler = default_executor().scheduler if isinstance(scheduler, rpc): addr = (scheduler.ip, scheduler.port) elif isinstance(scheduler, Scheduler): addr = ('127.0.0.1', scheduler.port) self.cds = ColumnDataSource({ k: [] for k in [ 'host', 'processing', 'stacks', 'waiting', 'zero', 'left', 'mid', 'right' ] }) self.display_notebook = False left_range = Range1d(0, 1) self.figure = figure(height=200, width=800, y_range=left_range) self.figure.extra_y_ranges = {'waiting': Range1d(start=0, end=1)} self.figure.add_layout( LinearAxis(y_range_name='waiting', axis_label='waiting'), 'right') self.figure.logo = None proc = self.figure.quad(legend='processing', left='left', right='mid', bottom='zero', top='nprocessing', source=self.cds, color=(0, 0, 255, 0.5)) wait = self.figure.quad(legend='waiting', left='mid', right='right', bottom='zero', top='waiting', source=self.cds, y_range_name='waiting', color=(255, 0, 0, 0.5)) self.figure.add_tools( HoverTool(renderers=[proc, wait], tooltips=[("host", "@host"), ("processing", "@processing"), ("waiting", "@waiting")])) self.future = self.update(addr, interval) if is_kernel() and not curstate().notebook: output_notebook() assert curstate().notebook
def show_figure(fig): from bokeh.document import Document from bokeh.io import curstate, show if fig.document is None: doc = Document() doc.add_root(fig) curstate().document = doc fig.__dict__["_handle"] = show(fig)
def __init__(self, addr=None, interval=1.00): if addr is None: scheduler = default_executor().scheduler if isinstance(scheduler, rpc): addr = (scheduler.ip, scheduler.port) elif isinstance(scheduler, Scheduler): addr = ('127.0.0.1', scheduler.port) self.cds = ColumnDataSource({ k: [] for k in ['host', 'cpu', 'memory', 'zero', 'left', 'mid', 'right'] }) self.display_notebook = False self.figure = figure(height=200, width=800, y_range=(0, 100)) self.figure.logo = None cpu = self.figure.quad(legend='cpu', left='left', right='mid', bottom='zero', top='cpu', source=self.cds, color=(0, 0, 255, 0.5)) memory = self.figure.quad(legend='memory', left='mid', right='right', bottom='zero', top='memory', source=self.cds, color=(255, 0, 0, 0.5)) self.figure.add_tools( HoverTool(renderers=[cpu, memory], tooltips=[("host", "@host"), ("cpu", "@cpu"), ("memory", "@memory")])) self.future = self.update(addr, interval) if is_kernel() and not curstate().notebook: output_notebook() assert curstate().notebook
def setup_chosen(fpath): try: df = pd.DataFrame.from_csv(fpath) except Exception as exc: msg = str(exc) MessageBox.text = msg dfcols = list(df.columns) ChosenSource = ColumnDataSource() ChosenSource.data = bu.column_data_source_data_from_df(df) ChosenSource.name = "ChosenSource" ChosenTable = bu.data_table(source=ChosenSource, columns=dfcols, width=800) ChosenTable.name = "ChosenTable" metadf = bu.df_summary(df) MetaSource = ColumnDataSource() MetaSource.name = "MetaSource" MetaSource.data = bu.column_data_source_data_from_df(metadf) MetaTable = bu.data_table(source=MetaSource, columns=list(metadf.columns), width=600) MetaTable.name = "MetaTable" RowFilter.value = ("# enter row filter conditions here") ScatterPlotX = Select(options = dfcols, value=dfcols[0]) ScatterPlotX.name = 'ScatterPlotX' ScatterPlotY = Select(options = dfcols, value=dfcols[-1]) ScatterPlotY.name = 'ScatterPlotY' ScatterSource = ColumnDataSource() ScatterSource.name = 'ScatterSource' ScatterSource.data = dict(X=ChosenSource.data[ScatterPlotX.value], Y=ChosenSource.data[ScatterPlotY.value]) ScatterPlot = Figure(height=500, width=600) res = ScatterPlot.scatter(x='X', y='Y', source=ScatterSource) res.name = "srender" ScatterPlot.name = 'ScatterPlot' layout= column(MessageBox, CloseButton, RowFilter, ColumnChooser, column(bu.child_in_widgetbox(MetaTable), bu.child_in_widgetbox(ChosenTable)), row(ScatterPlotX, ScatterPlotY, MakeScatterPlot), ScatterPlot,) MakeScatterPlot.on_click(functools.partial(make_scatter, dom=layout)) currentstate = bio.curstate() return layout
def __init__(self, addr=None, interval=1.00): if addr is None: scheduler = default_executor().scheduler if isinstance(scheduler, rpc): addr = (scheduler.ip, scheduler.port) elif isinstance(scheduler, Scheduler): addr = ('127.0.0.1', scheduler.port) self.cds = ColumnDataSource({k: [] for k in ['host', 'processing', 'stacks', 'waiting', 'zero', 'left', 'mid', 'right']}) self.display_notebook = False left_range = Range1d(0, 1) self.figure = figure(height=200, width=800, y_range=left_range) self.figure.extra_y_ranges = {'waiting': Range1d(start=0, end=1)} self.figure.add_layout(LinearAxis(y_range_name='waiting', axis_label='waiting'), 'right') self.figure.logo = None proc = self.figure.quad(legend='processing', left='left', right='mid', bottom='zero', top='nprocessing', source=self.cds, color=(0, 0, 255, 0.5)) wait = self.figure.quad(legend='waiting', left='mid', right='right', bottom='zero', top='waiting', source=self.cds, y_range_name='waiting', color=(255, 0, 0, 0.5)) self.figure.add_tools(HoverTool(renderers=[proc, wait], tooltips=[("host", "@host"), ("processing", "@processing"), ("waiting", "@waiting")])) self.future = self.update(addr, interval) if is_kernel() and not curstate().notebook: output_notebook() assert curstate().notebook
def test(self): self.assertEqual(io.curstate(), io._state)
import pandas as pd import numpy as np import numpy.matlib import matplotlib.pyplot as plt from yahoo_finance import Share from datetime import datetime from bokeh.models import DatetimeTickFormatter from datetime import timedelta def nix(val, lst): return [x for x in lst if x != val] # Let source be the data I am using to plot. curstate().autoadd = False # Create a dictionary for table source_table = ColumnDataSource(data=dict( Forecast=[], AQuarter=[], OneFourth=[], OneThird=[], TwoThird=[])) columnsD = [ TableColumn(field="Forecast", title="Days past Current"), TableColumn(field="AQuarter", title="96% Confidence"), TableColumn(field="OneFourth", title="80% Confidence"), TableColumn(field="OneThird", title="60% Confidence"), ] data_table = DataTable(source=source_table, columns=columnsD, width=1050, height=300, row_headers=False, editable=True)
#CloseButton.on_click(close_session) CloseButton.callback = close_browser_js TextBox.on_change("value", update_textbox) def set_message(text): global MessageBox MessageBox.text = text layout = column(MessageBox, TextBox, CloseButton) oldcurdoc = bio.curdoc() currentstate = bio.curstate() TheDoc = Document(title="NewDoc") TheDoc.add_root(layout) def get_function_name(stackpos=1): ''' call me to get your name :return: name of the calling function ''' # my_name = inspect.stack()[0][3] caller = inspect.stack()[stackpos][3] return caller def session_update(): msg = get_function_name()
def revive(self): self.terminated = False curstate().reset()
import json import sys import numpy as np from numpy import pi from bokeh.plotting import figure, output_file, show, ColumnDataSource from bokeh import palettes from bokeh.models import HoverTool,HBox, VBox, Select from bokeh.models.widgets import Dropdown from bokeh.io import output_file, show, vform, curdoc, curstate from bokeh.charts import Bar, Scatter import pandas as pd from bokeh.models.renderers import GlyphRenderer import pandas.core.series curstate().autoadd = False session = push_session(curdoc()) # read json file with open('data/content_data.json') as datafile: input_data = json.load(datafile) # extract attribute names data = input_data['data'] data_attributes = map(lambda a: a['attributes'], data) attributes_name = list(set([item['name'] for sublist in data_attributes for item in sublist])) # global state selected_attribute = attributes_name[1] selected_points = [] table_selected_attribute=selected_attribute
from bokeh.io import show, output_file, curstate from bokeh.plotting import figure from bokeh.models import Button, CustomJS from bokeh.layouts import column f1 = figure() f1.x(x=[1, 2, 3], y=[3, 2, 1]) main_row = column(f1) b = Button(label='Add plot', callback=CustomJS(args=dict(main_row=main_row), code=""" f = Bokeh.Plotting.figure(); f.cross({x: [1, 2, 3], y: [3, 2, 1]}); main_row.children.push(f); main_row.properties.children.change.emit(); """)) main_row.children.append(b) output_file('bokeh_add_plot_no_server.html') curstate().file['resources'].js_components.append('bokeh-api') show(main_row)