本文整理汇总了Python中bokeh.session.Session.object_link方法的典型用法代码示例。如果您正苦于以下问题:Python Session.object_link方法的具体用法?Python Session.object_link怎么用?Python Session.object_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bokeh.session.Session
的用法示例。
在下文中一共展示了Session.object_link方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DataTables
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import object_link [as 别名]
#.........这里部分代码省略.........
manufacturers = sorted(mpg["manufacturer"].unique())
models = sorted(mpg["model"].unique())
transmissions = sorted(mpg["trans"].unique())
drives = sorted(mpg["drv"].unique())
classes = sorted(mpg["class"].unique())
manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers)
manufacturer_select.on_change('value', self.on_manufacturer_change)
model_select = Select(title="Model:", value="All", options=["All"] + models)
model_select.on_change('value', self.on_model_change)
transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions)
transmission_select.on_change('value', self.on_transmission_change)
drive_select = Select(title="Drive:", value="All", options=["All"] + drives)
drive_select.on_change('value', self.on_drive_change)
class_select = Select(title="Class:", value="All", options=["All"] + classes)
class_select.on_change('value', self.on_class_change)
columns = [
TableColumn(field="manufacturer", header="Manufacturer", type="autocomplete", source=manufacturers),
TableColumn(field="model", header="Model", type="autocomplete", source=models),
TableColumn(field="displ", header="Displacement", type="numeric", format="0.00"),
TableColumn(field="year", header="Year", type="numeric"),
TableColumn(field="cyl", header="Cylinders", type="numeric"),
TableColumn(field="trans", header="Transmission", type="dropdown", strict=True, source=transmissions),
TableColumn(field="drv", header="Drive", type="autocomplete", strict=True, source=drives),
TableColumn(field="class", header="Class", type="autocomplete", strict=True, source=classes),
TableColumn(field="cty", header="City MPG", type="numeric"),
TableColumn(field="hwy", header="Highway MPG", type="numeric"),
]
handson_table = HandsonTable(source=self.source, columns=columns, sorting=True)
xdr = DataRange1d(sources=[self.source.columns("index")])
#xdr = FactorRange(factors=manufacturers)
ydr = DataRange1d(sources=[self.source.columns("cty"), self.source.columns("hwy")])
plot = Plot(title=None, data_sources=[self.source], x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
xaxis = LinearAxis(plot=plot)
plot.below.append(xaxis)
yaxis = LinearAxis(plot=plot)
ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
plot.left.append(yaxis)
cty = Glyph(data_source=self.source, glyph=Circle(x="index", y="cty", fill_color="green"))
hwy = Glyph(data_source=self.source, glyph=Circle(x="index", y="hwy", fill_color="red"))
select_tool = BoxSelectTool(renderers=[cty, hwy], select_y=False)
plot.tools.append(select_tool)
overlay = BoxSelectionOverlay(tool=select_tool)
plot.renderers.extend([cty, hwy, ygrid, overlay])
controls = VBox(children=[manufacturer_select, model_select, transmission_select, drive_select, class_select], width=200)
top_panel = HBox(children=[controls, plot])
layout = VBox(children=[top_panel, handson_table])
return layout
def on_manufacturer_change(self, obj, attr, _, value):
self.manufacturer_filter = None if value == "All" else value
self.update_data()
def on_model_change(self, obj, attr, _, value):
self.model_filter = None if value == "All" else value
self.update_data()
def on_transmission_change(self, obj, attr, _, value):
self.transmission_filter = None if value == "All" else value
self.update_data()
def on_drive_change(self, obj, attr, _, value):
self.drive_filter = None if value == "All" else value
self.update_data()
def on_class_change(self, obj, attr, _, value):
self.class_filter = None if value == "All" else value
self.update_data()
def update_data(self):
df = mpg
if self.manufacturer_filter:
df = df[df["manufacturer"] == self.manufacturer_filter]
if self.model_filter:
df = df[df["model"] == self.model_filter]
if self.transmission_filter:
df = df[df["trans"] == self.transmission_filter]
if self.drive_filter:
df = df[df["drv"] == self.drive_filter]
if self.class_filter:
df = df[df["class"] == self.class_filter]
self.source.data = ColumnDataSource.from_df(df)
self.session.store_document(self.document)
def run(self, poll_interval=0.5):
link = self.session.object_link(self.document.context)
print("Please visit %s to see the plots (press ctrl-C to exit)" % link)
try:
while True:
self.session.load_document(self.document)
time.sleep(poll_interval)
except KeyboardInterrupt:
print()
except ConnectionError:
print("Connection to bokeh-server was terminated")
示例2: VBoxModelForm
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import object_link [as 别名]
country_select.on_change('value', on_country_change)
controls = VBoxModelForm(_children=[Paragraph(text="Date Range"),
Paragraph(text=""), # spacing hack
Paragraph(text=""),
date_select, country_select])
vboxsmall = VBoxModelForm(_children=[controls, source_par])
#hbox1 = HBox(children=[job_loc_plot_builder(), vboxsmall])
#hbox2 = HBox(children=[weekday_builder(), jobtype_builder()])
#layout = VBox(children=[hbox1, hbox2])
layout = VBox(children=[vboxsmall])
return layout
obj = layout()
document.add(obj)
update_data()
if __name__ == "__main__":
link = session.object_link(obj)
print("Please visit %s to see the plots" % link)
try:
while True:
session.load_document(document)
time.sleep(0.5)
except KeyboardInterrupt:
print()
except ConnectionError:
print("Connection to bokeh-server was terminated")
示例3: DataTables
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import object_link [as 别名]
#.........这里部分代码省略.........
manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers)
manufacturer_select.on_change('value', self.on_manufacturer_change)
model_select = Select(title="Model:", value="All", options=["All"] + models)
model_select.on_change('value', self.on_model_change)
transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions)
transmission_select.on_change('value', self.on_transmission_change)
drive_select = Select(title="Drive:", value="All", options=["All"] + drives)
drive_select.on_change('value', self.on_drive_change)
class_select = Select(title="Class:", value="All", options=["All"] + classes)
class_select.on_change('value', self.on_class_change)
columns = [
TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")),
TableColumn(field="model", title="Model", editor=StringEditor(completions=models)),
TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")),
TableColumn(field="year", title="Year", editor=IntEditor()),
TableColumn(field="cyl", title="Cylinders", editor=IntEditor()),
TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)),
TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)),
TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)),
TableColumn(field="cty", title="City MPG", editor=IntEditor()),
TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()),
]
data_table = DataTable(source=self.source, columns=columns, editable=True)
xdr = DataRange1d()
ydr = DataRange1d()
plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300)
xaxis = LinearAxis(plot=plot)
plot.below.append(xaxis)
yaxis = LinearAxis(plot=plot)
ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
plot.left.append(yaxis)
cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5)
hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5)
cty = GlyphRenderer(data_source=self.source, glyph=cty_glyph)
hwy = GlyphRenderer(data_source=self.source, glyph=hwy_glyph)
tooltips = [
("Manufacturer", "@manufacturer"),
("Model", "@model"),
("Displacement", "@displ"),
("Year", "@year"),
("Cylinders", "@cyl"),
("Transmission", "@trans"),
("Drive", "@drv"),
("Class", "@class"),
]
cty_hover_tool = HoverTool(plot=plot, renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")])
hwy_hover_tool = HoverTool(plot=plot, renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")])
select_tool = BoxSelectTool(plot=plot, renderers=[cty, hwy], dimensions=['width'])
plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool])
plot.renderers.extend([cty, hwy, ygrid])
controls = VBox(children=[manufacturer_select, model_select, transmission_select, drive_select, class_select], width=200)
top_panel = HBox(children=[controls, plot])
layout = VBox(children=[top_panel, data_table])
return layout
def on_manufacturer_change(self, obj, attr, _, value):
self.manufacturer_filter = None if value == "All" else value
self.update_data()
def on_model_change(self, obj, attr, _, value):
self.model_filter = None if value == "All" else value
self.update_data()
def on_transmission_change(self, obj, attr, _, value):
self.transmission_filter = None if value == "All" else value
self.update_data()
def on_drive_change(self, obj, attr, _, value):
self.drive_filter = None if value == "All" else value
self.update_data()
def on_class_change(self, obj, attr, _, value):
self.class_filter = None if value == "All" else value
self.update_data()
def update_data(self):
df = mpg
if self.manufacturer_filter:
df = df[df["manufacturer"] == self.manufacturer_filter]
if self.model_filter:
df = df[df["model"] == self.model_filter]
if self.transmission_filter:
df = df[df["trans"] == self.transmission_filter]
if self.drive_filter:
df = df[df["drv"] == self.drive_filter]
if self.class_filter:
df = df[df["class"] == self.class_filter]
self.source.data = ColumnDataSource.from_df(df)
self.session.store_document(self.document)
def run(self, do_view=False, poll_interval=0.5):
link = self.session.object_link(self.document.context)
print("Please visit %s to see the plots" % link)
if do_view: view(link)
print("\npress ctrl-C to exit")
self.session.poll_document(self.document)
示例4: Dropdown
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import object_link [as 别名]
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)
radio_group = RadioGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_group.on_click(radio_group_handler)
checkbox_button_group = CheckboxButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_button_group.on_click(checkbox_button_group_handler)
radio_button_group = RadioButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_button_group.on_click(radio_button_group_handler)
vbox = VBox(children=[button, toggle, dropdown, split, checkbox_group, radio_group, checkbox_button_group, radio_button_group])
document.add(vbox)
session.store_document(document)
if __name__ == "__main__":
link = session.object_link(document.context)
print("Please visit %s to see the plots" % link)
view(link)
print("\npress ctrl-C to exit")
session.poll_document(document)
示例5: Dashboard
# 需要导入模块: from bokeh.session import Session [as 别名]
# 或者: from bokeh.session.Session import object_link [as 别名]
#.........这里部分代码省略.........
self.init_sources()
self.document.add(self.construct())
# Sources
# -------
def init_sources(self):
"""Initialize DataSource objects backing the dashboard elements."""
columns = ['some', 'column', 'headers']
self.columns = columns
self.data_source = ColumnDataSource(data=dict(zip(columns, []*len(columns))))
# Construction
# ------------
def construct(self):
slider = self.slider()
plot = self.plot()
handson_table = self.handson_table()
layout = VBox(children=[
slider,
plot,
handson_table
])
return layout
# Widgets
# -------
def slider(self):
slider = Slider(value=10, start=10, end=100, step=10, orientation="horizontal", title="Slider")
slider.on_change('value', self.on_slider_change)
return HBox(children=[slider], width=500)
def on_slider_change(self, obj, attr, old, new):
def handson_table(self):
# Hands On Table Widget
columns = [
TableColumn(field="a", header="A"),
TableColumn(field="b", header="B"),
TableColumn(field="c", header="C"),
]
return HandsonTable(source=self.data_source, columns=columns, width=800)
# Plots
# -----
def plot(self):
plot = curplot()
hover = plot.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([
("type", " @type"),
])
seabornify(plot)
return plot
# Update Routine
# --------------
def update(self):
self.session.store_objects(self.data_source)
# Run
# ---
def run(self, poll_interval=1):
self.session.store_document(self.document)
link = self.session.object_link(self.document.context)
if self.show:
import webbrowser
webbrowser.open(link)
else:
print("Please visit %s to see the plots (press ctrl-C to exit)" % link)
try:
while True:
self.session.load_document(self.document)
sleep(poll_interval)
except KeyboardInterrupt:
print()
except ConnectionError:
print("Connection to bokeh-server was terminated.")
if __name__ == "__main__":
args = parse_args()
dashboard = Dashboard(**vars(args))
dashboard.run()