Here are the examples of the python api bokeh.models.Dropdown taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
0
View Source File : dataset.py
License : MIT License
Project Creator : phurwicz
License : MIT License
Project Creator : phurwicz
def setup_widgets(self):
"""
???+ note "Create `bokeh` widgets for interactive data management."
Operations:
- PUSH: push updated dataframes to linked `explorer`s.
- COMMIT: added selected points to a specific subset `dataframe`.
- DEDUP: cross-deduplicate across all subset `dataframe`s.
- VIEW: view selected points of linked `explorer`s.
- the link can be different from that for PUSH. Typically all the `explorer`s sync their selections, and only an `annotator` is linked to the `dataset`.
- PATCH: update a few edited rows from VIEW result to the dataset.
- EVICT: remove a few rows from both VIEW result and linked `explorer` selection.
"""
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",
)
self.selection_viewer = Button(
label="View Selected",
button_type="primary",
height_policy="fit",
width_policy="min",
)
self.selection_patcher = Button(
label="Update Row Values",
button_type="warning",
height_policy="fit",
width_policy="min",
)
self.selection_evictor = Button(
label="Evict Rows from Selection",
button_type="primary",
height_policy="fit",
width_policy="min",
)
def commit_base_callback():
"""
COMMIT creates cross-duplicates between subsets.
Changes dataset rows.
No change to explorers.
- PUSH shall be blocked until DEDUP is executed.
- PATCH shall be blocked until PUSH is executed.
- EVICT shall be blocked until PUSH is executed.
"""
self.dedup_trigger.disabled = False
self.update_pusher.disabled = True
self.selection_patcher.disabled = True
self.selection_evictor.disabled = True
def dedup_base_callback():
"""
DEDUP re-creates dfs with different indices than before.
Changes dataset rows.
No change to explorers.
- COMMIT shall be blocked until PUSH is executed.
- PATCH shall be blocked until PUSH is executed.
- EVICT shall be blocked until PUSH is executed.
"""
self.update_pusher.disabled = False
self.data_committer.disabled = True
self.selection_patcher.disabled = True
self.selection_evictor.disabled = True
self.df_deduplicate()
def push_base_callback():
"""
PUSH enforces df consistency with all linked explorers.
No change to dataset rows.
Changes explorers.
- DEDUP could be blocked because it stays trivial until COMMIT is executed.
"""
self.data_committer.disabled = False
self.dedup_trigger.disabled = True
# empty the selection table, then allow PATCH and EVICT
self.sel_table.source.data = dict()
self.sel_table.source.selected.indices = []
self.selection_patcher.disabled = False
self.selection_evictor.disabled = False
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 view(self):
0
View Source File : dataset.py
License : MIT License
Project Creator : phurwicz
License : MIT License
Project Creator : phurwicz
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()
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 Pandas DataFrame version to {export_path}")
# assign the callback, keeping its reference
self._callback_export = callback_export
self.file_exporter.on_click(self._callback_export)
def setup_pop_table(self, **kwargs):
0
View Source File : base.py
License : MIT License
Project Creator : phurwicz
License : MIT License
Project Creator : phurwicz
def _setup_axes_dropdown(self):
"""
???+ note "Find embedding fields and allow any of them to be set as the x or y axis."
"""
from bokeh.models import Dropdown
embed_cols = self.find_embedding_fields()
init_x, init_y = embed_cols[:2]
self.dropdown_x_axis = Dropdown(label=f"X coord: {init_x}", menu=embed_cols)
self.dropdown_y_axis = Dropdown(label=f"Y coord: {init_y}", menu=embed_cols)
def change_x(event):
self.dropdown_x_axis.label = f"X coord: {event.item}"
for _renderer in self.figure.renderers:
_renderer.glyph.x = event.item
def change_y(event):
self.dropdown_y_axis.label = f"Y coord: {event.item}"
for _renderer in self.figure.renderers:
_renderer.glyph.y = event.item
self.dropdown_x_axis.on_click(change_x)
self.dropdown_y_axis.on_click(change_y)
# consider allowing dynamic menu refreshment
# def refresh_axes_list():
# embed_cols = self.find_embedding_fields()
# self.dropdown_x_axis.menu = embed_cols[:]
# self.dropdown_y_axis.menu = embed_cols[:]
def value_patch_by_slider(self, col_original, col_patch, **kwargs):
0
View Source File : functionality.py
License : MIT License
Project Creator : phurwicz
License : MIT License
Project Creator : phurwicz
def _subroutine_setup_lf_apply_trigger(self):
"""
???+ note "Create widget for applying LFs on data."
"""
self.lf_apply_trigger = Dropdown(
label="Apply Labels",
button_type="warning",
menu=list(self.lf_data.keys()),
height_policy="fit",
width_policy="min",
)
def callback_apply(event):
"""
A callback on clicking the 'self.lf_apply_trigger' button.
Update labels in the source similarly to the annotator.
However, in this explorer, because LFs already use color, the produced labels will not.
"""
lf = self.lf_data[event.item]["lf"]
assert callable(lf), f"Expected a function, got {lf}"
selected_idx = self.sources["raw"].selected.indices
if not selected_idx:
self._warn(
"attempting labeling by function: did not select any data points. Eligible subset is 'raw'."
)
return
labels = self.dfs["raw"].iloc[selected_idx].apply(lf, axis=1).values
num_nontrivial = len(
list(filter(lambda l: l != module_config.ABSTAIN_DECODED, labels))
)
# update label in both the df and the data source
self.dfs["raw"].loc[selected_idx, "label"] = labels
for _idx, _label in zip(selected_idx, labels):
_idx = int(_idx)
self.sources["raw"].patch({"label": [(_idx, _label)]})
self._info(
f"applied {num_nontrivial}/{len(labels)} annotations by func {lf.name}"
)
self.lf_apply_trigger.on_click(callback_apply)
def _subroutine_setup_lf_filter_trigger(self):
0
View Source File : functionality.py
License : MIT License
Project Creator : phurwicz
License : MIT License
Project Creator : phurwicz
def _subroutine_setup_lf_filter_trigger(self):
"""
???+ note "Create widget for using LFs to filter data."
"""
self.lf_filter_trigger = Dropdown(
label="Use as Selection Filter",
button_type="primary",
menu=list(self.lf_data.keys()),
height_policy="fit",
width_policy="min",
)
def callback_filter(event):
"""
A callback on clicking the 'self.lf_filter_trigger' button.
Update selected indices in a one-time manner.
"""
lf = self.lf_data[event.item]["lf"]
assert callable(lf), f"Expected a function, got {lf}"
for _key, _source in self.sources.items():
_selected = _source.selected.indices
_labels = self.dfs[_key].iloc[_selected].apply(lf, axis=1).values
_kept = [
_idx
for _idx, _label in zip(_selected, _labels)
if _label != module_config.ABSTAIN_DECODED
]
self.sources[_key].selected.indices = _kept
self.lf_filter_trigger.on_click(callback_filter)
def _postprocess_sources(self):