Here are the examples of the python api bokeh.models.Tabs taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
View Source File : trace.py
License : MIT License
Project Creator : spirali
License : MIT License
Project Creator : spirali
def plot_tabs(trace_events, workers, plot_fns, labels):
from bokeh.models import Panel, Tabs
return Tabs(tabs=[Panel(child=fn(trace_events, workers), title=label)
for (fn, label) in zip(plot_fns, labels)])
def plot_all(trace_events, workers):
0
View Source File : client.py
License : GNU General Public License v3.0
Project Creator : happydasch
License : GNU General Public License v3.0
Project Creator : happydasch
def _createmodel(self):
def on_select_filter(self, a, old, new):
_logger.debug(f'Switching filter to {new}...')
# ensure datahandler is stopped
self._datahandler.stop()
self._filter = new
self.updatemodel()
_logger.debug('Switching filter finished')
def on_click_nav_action(self):
if not self._paused:
self._pause()
else:
self._resume()
refresh(self)
def on_click_nav_prev(self, steps=1):
self._pause()
self._set_data_by_idx(self._datahandler.get_last_idx() - steps)
update_nav_buttons(self)
def on_click_nav_next(self, steps=1):
self._pause()
self._set_data_by_idx(self._datahandler.get_last_idx() + steps)
update_nav_buttons(self)
def refresh(self):
self.doc.add_next_tick_callback(partial(update_nav_buttons, self))
def reset_nav_buttons(self):
btn_nav_prev.disabled = True
btn_nav_next.disabled = True
btn_nav_action.label = '❙❙'
def update_nav_buttons(self):
last_idx = self._datahandler.get_last_idx()
last_avail_idx = self._app.get_last_idx(self._figid)
if last_idx < self.lookback:
btn_nav_prev.disabled = True
btn_nav_prev_big.disabled = True
else:
btn_nav_prev.disabled = False
btn_nav_prev_big.disabled = False
if last_idx >= last_avail_idx:
btn_nav_next.disabled = True
btn_nav_next_big.disabled = True
else:
btn_nav_next.disabled = False
btn_nav_next_big.disabled = False
if self._paused:
btn_nav_action.label = '▶'
else:
btn_nav_action.label = '❙❙'
# filter selection
datanames = get_datanames(self._strategy)
options = [('', 'Strategy')]
for d in datanames:
options.append(('D' + d, f'Data: {d}'))
options.append(('G', 'Plot Group'))
self._filter = 'D' + datanames[0]
select_filter = Select(
value=self._filter,
options=options)
select_filter.on_change(
'value',
partial(on_select_filter, self))
# nav
btn_nav_prev = Button(label='❮', width=self.NAV_BUTTON_WIDTH)
btn_nav_prev.on_click(partial(on_click_nav_prev, self))
btn_nav_prev_big = Button(label='❮❮', width=self.NAV_BUTTON_WIDTH)
btn_nav_prev_big.on_click(partial(on_click_nav_prev, self, 10))
btn_nav_action = Button(label='❙❙', width=self.NAV_BUTTON_WIDTH)
btn_nav_action.on_click(partial(on_click_nav_action, self))
btn_nav_next = Button(label='❯', width=self.NAV_BUTTON_WIDTH)
btn_nav_next.on_click(partial(on_click_nav_next, self))
btn_nav_next_big = Button(label='❯❯', width=self.NAV_BUTTON_WIDTH)
btn_nav_next_big.on_click(partial(on_click_nav_next, self, 10))
# layout
controls = row(
children=[select_filter])
nav = row(
children=[btn_nav_prev_big,
btn_nav_prev,
btn_nav_action,
btn_nav_next,
btn_nav_next_big])
# tabs
tabs = Tabs(
id='tabs',
sizing_mode=self._app.scheme.plot_sizing_mode)
# model
model = layout(
[
# app settings, top area
[column(controls, width_policy='min'),
Spacer(),
column(nav, width_policy='min')],
Spacer(height=15),
# layout for tabs
[tabs]
],
sizing_mode='stretch_width')
return model, partial(refresh, self)
def updatemodel(self):
0
View Source File : views.py
License : MIT License
Project Creator : mwang87
License : MIT License
Project Creator : mwang87
def compoundenrichment():
blacklist_attributes = ["ATTRIBUTE_DatasetAccession", "ATTRIBUTE_Curated_BodyPartOntologyIndex", "filename", "UniqueSubjectID", "UBERONOntologyIndex", "SubjectIdentifierAsRecorded", "SampleCollectionDateandTime", "LatitudeandLongitude", "InternalStandardsUsed", "DepthorAltitudeMeters", "DOIDOntologyIndex", "Country", "ComorbidityListDOIDIndex", "AgeInYears"]
compoundname = request.form['compoundname']
compound_db = Compound.select().where(Compound.compoundname == compoundname)
compound_filenames = [filename.filepath for filename in Filename.select().join(CompoundFilenameConnection).where(CompoundFilenameConnection.compound==compound_db)]
enrichment_list = []
if "filenames" in request.form:
filter_filenames = set(json.loads(request.form["filenames"]))
if len(filter_filenames) == 0:
filter_filenames = set([filename.filepath for filename in Filename.select()])
else:
filter_filenames = set([filename.filepath for filename in Filename.select()])
all_metadata = FilenameAttributeConnection.select(Attribute.categoryname, AttributeTerm.term, fn.COUNT(FilenameAttributeConnection.filename).alias('ct')).join(Attribute).switch(FilenameAttributeConnection).join(AttributeTerm).group_by(Attribute.categoryname, AttributeTerm.term).dicts()
for attribute_term_pair in all_metadata:
# if attribute_term_pair["categoryname"].find("ATTRIBUTE_") == -1:
# continue
if attribute_term_pair["categoryname"] in blacklist_attributes:
continue
attribute_files_db = Filename.select().join(FilenameAttributeConnection).where(FilenameAttributeConnection.attributeterm == attribute_term_pair["term"]).where(FilenameAttributeConnection.attribute == attribute_term_pair["categoryname"])
attribute_filenames = set([filename.filepath for filename in attribute_files_db]).intersection(filter_filenames)
if len(attribute_filenames) > 0:
intersection_filenames = set(compound_filenames).intersection(set(attribute_filenames)).intersection(filter_filenames)
enrichment_dict = {}
enrichment_dict["attribute_name"] = attribute_term_pair["categoryname"]
enrichment_dict["attribute_term"] = attribute_term_pair["term"]
enrichment_dict["totalfiles"] = len(attribute_filenames)
enrichment_dict["compoundfiles"] = len(intersection_filenames)
enrichment_dict["percentage"] = len(intersection_filenames)/float(len(attribute_filenames))
enrichment_list.append(enrichment_dict)
enrichment_list = sorted(enrichment_list, key=lambda list_object: list_object["percentage"], reverse=True)
# Creating Bokeh Plot Here
enrichment_df = pd.DataFrame(enrichment_list)
# Finding all non-zero entries
enrichment_df = enrichment_df[enrichment_df["totalfiles"] != 0]
all_attributes = list(set(list(enrichment_df["attribute_name"])))
from bokeh.models import Panel, Tabs
from bokeh.plotting import figure
from bokeh.embed import components
all_tabs = []
for attribute in all_attributes:
filtered_df = enrichment_df[enrichment_df["attribute_name"] == attribute]
filtered_df = filtered_df[filtered_df["percentage"] > 0]
all_terms = list(filtered_df["attribute_term"])
all_percentage = list(filtered_df["percentage"])
plot = figure(x_range=all_terms, plot_height=300, plot_width=1200, sizing_mode="scale_width", title="{} Percentage of Terms".format(attribute))
plot.vbar(x=all_terms, top=all_percentage, width=0.9)
tab = Panel(child=plot, title=attribute)
all_tabs.append(tab)
tabs = Tabs(tabs=all_tabs)
script, div = components(tabs)
drawing_dict = {}
drawing_dict["div"] = div
drawing_dict["script"] = script
return_dict = {}
return_dict["enrichment_list"] = enrichment_list
return_dict["drawings"] = drawing_dict
return json.dumps(return_dict)
@app.route('/filesenrichment', methods=['POST'])