Skip to content Skip to sidebar Skip to footer

How To Plot Bar Graph Interactively Based On Value Of Dropdown Widget In Bokeh Python?

I want to plot the bar graph based value of dropdown widget. Code import pandas as pd from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.w

Solution 1:

For 1.) you are referencing it before assigning it. Look at the df['item']==dropdown.value inside the square brackets. That happens first before the assignment. As to why this matters, that's how Python works. All assignments in a function by default create local variables. But before the assignment, only the global value is available. Python is telling you it won't allow mixed global/local usage in a single function. Long story short, rename the df variable inside the function:

subset = df[df['item']==dropdown.value]    
p = Bar(subset, ...) 

For 2.) you need to put things in a layout (e.g. a column). There are lots of example of this in the project docs and in the gallery.

Post a Comment for "How To Plot Bar Graph Interactively Based On Value Of Dropdown Widget In Bokeh Python?"