简体   繁体   中英

Bokeh Select Widget to Update Plot

I am trying to build a grid plot that updates based on value selected from 'Select' widget using Bokeh. The graph works but there is no interaction between the widget and the graph. I am not sure how to do this. The goal is to use the 'Select' to update dfPlot then follow the remaining steps.

Here is what i have so far:

output_file('layout.html')

select = Select(title="Option:", options= list(dfExpense['Ident'].unique()), value= "VALUE")

def update_plot(attr, old, new):
    dfPlot = dfExpense[dfExpense['Ident'] == select.value]

select.on_change('value', update_plot)

d = []

for x in dfPlot['Account'].unique():
    d.append(f's_{x}')

plt = []

for i, x in enumerate(dfPlot['Account'].unique()):
    dftemp = dfPlot[dfPlot['Account']==gl]
    source1 = ColumnDataSource(dftemp)
    d[i] = figure(plot_width = 250, plot_height = 250)
    d[i].circle('X', 'Amount', source = source1)
    plt.append(d[i])
    
grid= gridplot([i for i in plt], ncols = 6)
l = row(grid, select)
show(l)

curdoc().add_root(l)

Thanks!

Someone else will probably give you a better answer. I'll just say, I think you might be doing things completely wrong for what you are trying to do (I did the same thing when starting to work with Bokeh).

My understanding after a bit of experience with Bokeh, as it relates to your problem, is as follows:

I had a similar problem, wanting interactivity without using a Python Bokeh server. CustomJS ended up serving my needs quite well, and even though I'm a novice at Javascript, they make it pretty easy (well, especially if your problem is similar to the examples, it can get tricky otherwise but still not very hard).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM