Kyle
Kyle

Reputation: 183

Bokeh Figure won't Update?

I'm new to Bokeh and was wondering if anyone could lend a little help tell me why my plot is not updating? The code is very simple, and can be found here:

http://pastebin.com/MLAigEG6

The code is just supposed to grab some data using the function "get_dataset", plot a bar chart, and let me update the plot using a dropdown box and slider. The two small dataframes can be found here:

https://github.com/degravek/bdata

The slider is set to default at 15 (30 total values plotted). If the slider is moved, or if the dropdown box is changed, the axes for the plot don't update for some reason. For example, if the slider is set to 2, there should only be 2 bars shown, and the axes should adjust accordingly. Thanks a lot for taking a look.

Upvotes: 2

Views: 1195

Answers (1)

Pablo Reyes
Pablo Reyes

Reputation: 3123

Nice code. In your update function, you also need to update the x_range.factors of the plot. And global asdata is not needed here.

def update_samples_or_dataset(attrname, old, new):
    dataset = dataset_select.value
    n_samples = int(samples_slider.value)

    asdata = get_dataset(dataset, n_samples)
    plot.x_range.factors = asdata['aspects'].tolist() # this was missing
    source.data = dict(x=asdata['aspects'].tolist(), y=asdata['importance'].values)

Upvotes: 2

Related Questions