Why is Select widget not working in bokeh?

by Sophia Song   Last Updated August 14, 2019 00:26 AM

I've been trying to create a dashboard of stock market information using bokeh, and I would like to have a dropdown menu that, when you click on one of the options, would change the information plotted depending on what you click.

The graph appears fine, but I can't get it to change using the dropdown menu.

Initially I thought it was a bokeh server problem. Now I've ran the "bokeh serve" command in anaconda prompt, and found this example: https://github.com/bokeh/bokeh/blob/1.3.4/examples/howto/server_embed/notebook_embed.ipynb that works exactly the way I want it to work when I copy and paste the code into my jupyter notebook. However, when I modify the code to my own data and use Select instead of Slider, the old problem appears.


def modify_dc(doc):

    source = ColumnDataSource(dat[['Date','Close']])

    #Making the glyphs
    big = figure(x_axis_type='datetime', title="Zeiss stock dashboard")
    p = big.line(x = "Date", y = "Close", line_width=2, source=source)

    def update(attr, old, new):
        if new == 'a':
            data = dat[['Date','Traded Volume']]
            data = dat[['Date','Close']]
        source1 = ColumnDataSource(data=data)
        r.data_source.data = source1.data

    menu = Select(options = ['a','b','c','d'],



There were no error messages of any sort. Anyone can help?

Tags : python bokeh

Answers 1

Don't do this:

r.data_source.data = source1.data

Although it looks like a "regular" Python dict, the ".data" attribute of a ColumnDataSource is actually a very specialized object that handles all the automatic synchronization between Python and JavaScript. Moving a .data from one CDS to another basically does not work, and, starting with Bokeh 2.0 later this year, trying to do so will raise an exception.

Instead, you can set a CDS .data from a plain Python dict:

source.data = { ... }

or in recent versions, directly from a Pandas DataFrame:

source.data = some_df
August 14, 2019 00:25 AM

Related Questions

How to create a Bokeh DataTable DateTime formatter?

Updated February 23, 2017 16:26 PM

Slider for bin size for a histogram in bokeh

Updated August 01, 2017 15:26 PM

Bokeh "source" with different columns length

Updated February 19, 2017 22:26 PM