How to change data of vbar glyph from outside a bokeh server

Hi guys,

In my project I am using Flask together with a Bokeh-server in order to use Bokeh-widgets, but in this case I need to update the plot depending on the employer name I get from a html form. Updating title and x_range as shown below works totally fine, but instead of replacing the old vbar I am just adding a new one.

Is there a way of removing the old vbar or changing the data of the old vbar directly?

Thank you very much for any help and if you need more information please let me know!


bokeh == 1.1.0
flask == 1.0.2
OS == macOS 10.14.4

@app.route('/visits_chart', methods=['GET'])
def visits_chart():
 employer_name = request.args.get('employer_name')
 session = pull_session(url='http://' + config.bokeh_IP + ':5006/visits_plot')
 script = server_session(, url='http://' + config.bokeh_IP + ':5006/visits_plot')

 employer_id = queries.get_employer_id(employer_name)
 new_data = utils.get_value_dict('Number of Visits|' + str(employer_id), config.Visit.default_time_interval, '', '')

 session.document.roots[0].children[0].x_range.factors = list(new_data['number_of_names'])
 session.document.roots[0].children[0].title.text = employer_name
 session.document.roots[0].children[0].vbar(x='number_of_names', top='count', width=0.5, bottom=0, color='#9ACD32',

 push_session(document=session.document, session_id='v2sv9095MUCX01tmFcMgY0wX4GWx3oarRzgUhofVgiYH', 
 url='http://' + config.bokeh_IP + ':5006/visits_plot')

 return render_template('visits_chart.html', script=script, template='Flask', employer_name=employer_name)

If you pass a name parameter to vbar whenever you originally create it:

plot.vbar(..., name="somename")

Then, assuming you make sure not to configure any other object with the same name, you can get at the data source in order to update the bar using:

plot = session.document.roots[0].children[0]
source = plot.select_one(dict(name="somename")).data_source = ...

Ahh thats very helpfull. Thanks a lot!