Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make .selected a proper Bokeh model #6845

crashMOGWAI opened this issue Aug 30, 2017 · 1 comment · Fixed by #7261

Make .selected a proper Bokeh model #6845

crashMOGWAI opened this issue Aug 30, 2017 · 1 comment · Fixed by #7261


Copy link

crashMOGWAI commented Aug 30, 2017

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.

proper  #selected

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)
        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 =
        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()
    source.on_change('selected', cb_change)
    worksheet = layout([[p1]], sizing_mode='fixed')
    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)

if __name__ == '__main__':
@crashMOGWAI crashMOGWAI changed the title Feature: Make .selected a proper Bokeh model Feature Request: Make .selected a proper Bokeh model Aug 31, 2017
Copy link

bryevdv commented Sep 5, 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.

@bryevdv bryevdv added this to the short-term milestone Sep 5, 2017
@clairetang6 clairetang6 self-assigned this Sep 28, 2017
@mattpap mattpap changed the title Feature Request: Make .selected a proper Bokeh model Make .selected a proper Bokeh model Sep 28, 2017
@bryevdv bryevdv modified the milestones: short-term, 0.12.15 Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging a pull request may close this issue.

3 participants