You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems to be a pain point with users, and I've stumbled into as well. Resetting the whole .selected dict seems to trigger updates in most simple cases, but reliability is finicky at best with more complex selection updates. @bryevdvYour idea, not mine.
Currently the only way to spoof this type of selection function is to create multiple grouped sources and manipulate the selection/nonselection attributes, or stack multiple sources and use the filters. It starts to get out of hand when dealing with larger data sets. Rather than dealing with multiple sources, a single data source paired with a callback that sets the .selected index based on a selection within that group, and reliable plot update trigger is preferred. @clairetang6 Maybe a CDSView extension concept, SelectFilter?
This standalone would select groups accordingly if .selected could detect an internal change and push an update trigger.
def mod_doc(doc):
''''''
import numpy as np
from bokeh.plotting import figure
from bokeh.layouts import layout
from bokeh.models import ColumnDataSource
from bokeh.sampledata.iris import flowers
from bokeh.palettes import Spectral6
from bokeh.transform import factor_cmap
source = ColumnDataSource(flowers)
plot_size_and_tools = {
'plot_height': 500, 'plot_width': 500,
'tools':['box_select','tap','reset', 'help']
}
p1 = figure(title="Proper .selected", **plot_size_and_tools)
p1.circle(
x='petal_length', y='petal_width', source=source,
color=factor_cmap('species', palette=Spectral6[3:],
factors=list(set(flowers.species))), size=10)
def cb_change(attr,old,new):
data = source.data.copy()
selected = source.selected.copy()
species = np.asarray(data['species'])
idx = selected['1d']['indices']
if len(idx) != 0:
selected['1d']['indices'] = []
species_sel = list(set(species[idx]))
for each in species_sel:
idx = np.where(species == each)[0].tolist()
selected['1d']['indices'].extend(idx)
source.selected.update(selected)
source.on_change('selected', cb_change)
worksheet = layout([[p1]], sizing_mode='fixed')
doc.add_root(worksheet)
return doc
def main():
''''''
from tornado.ioloop import IOLoop
from bokeh.document import Document
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.server.server import Server
io_loop = IOLoop.current()
doc = Document()
app = Application(FunctionHandler(mod_doc))
server = Server({'/proper.selected': app}, io_loop=io_loop, port=0)
server.start()
io_loop.add_callback(server.show,'/proper.selected')
io_loop.start()
if __name__ == '__main__':
main()
The text was updated successfully, but these errors were encountered:
crashMOGWAI
changed the title
Feature: Make .selected a proper Bokeh model
Feature Request: Make .selected a proper Bokeh model
Aug 31, 2017
This has definitely been discussed, and I think generally agreed upon. (I thought there was an issue already but I can't find it) The only main concern is finding a way to do it with as clean a deprecation path as possible, so that years worth of examples do not break overnight without warning.
Once @clairetang6 is back, she will be a good person to weigh in on this, as it intersects some of the work recently done of CDS views.
This seems to be a pain point with users, and I've stumbled into as well. Resetting the whole .selected dict seems to trigger updates in most simple cases, but reliability is finicky at best with more complex selection updates. @bryevdv Your idea, not mine.
Currently the only way to spoof this type of selection function is to create multiple grouped sources and manipulate the selection/nonselection attributes, or stack multiple sources and use the filters. It starts to get out of hand when dealing with larger data sets. Rather than dealing with multiple sources, a single data source paired with a callback that sets the .selected index based on a selection within that group, and reliable plot update trigger is preferred. @clairetang6 Maybe a CDSView extension concept, SelectFilter?
This standalone would select groups accordingly if .selected could detect an internal change and push an update trigger.
The text was updated successfully, but these errors were encountered: