2

I'm using this code to make a interactive map on python:

# Define the callback: update_plot
def update_plot(attr, old, new):

    # Create a dropdown Select widget for the y data: y_select
    N = str(select.value)
    map_options = GMapOptions(lat=sites_list_c.loc[sites_list_c['Site Name'] == N,'Latitude Decimal'], lng=sites_list_c.loc[sites_list_c['Site Name'] == N,'Lontitude Decimal'], map_type="roadmap", zoom=4)
    plot = gmap(my_key, map_options, title="Test")
    source = ColumnDataSource(
        data=dict( lat=sites_list_c['Latitude Decimal'].tolist(),
        lon=sites_list_c['Longitude Decimal'].tolist()
        )       
    )
    plot.circle(x="lon", y="lat", size=15, fill_color='blue', fill_alpha=0.8, source=source)

# Attach the update_plot callback to the 'value' property of y_select
select.on_change('value', update_plot)

# Create layout and add to current document
layout = row(widgetbox(select), plot)
curdoc().add_root(layout)
show(layout)

But, I'm getting this warning:

WARNING:bokeh.embed.util:
You are generating standalone HTML/JS output, but trying to use real Python
callbacks (i.e. with on_change or on_event). This combination cannot work.

Only JavaScript callbacks may be used with standalone output. For more
information on JavaScript callbacks with Bokeh, see:

   http://docs.bokeh.org/en/latest/docs/user_guide/interaction/callbacks.html

Alternatively, to use real Python callbacks, a Bokeh server application may
be used. For more information on building and running Bokeh applications, see:

http://docs.bokeh.org/en/latest/docs/user_guide/server.html
bigreddot
  • 33,642
  • 5
  • 69
  • 122

1 Answers1

4

The message attempts to be self explanatory. In order to connect real python callbacks to UI events, there has to be a real Python process running to execute the callback code. That process is the Bokeh server, and to use it you would run your code similar to:

bokeh serve --show app.py

And more specifically, you would not just execute python app.py

(Note you will need to remove the call to show as well, since it is not usable with Bokeh server apps.)

Otherwise, if you just run this like a regular python script (and with the show call) then Bokeh generates static HTML+JS output. There can be no way for a Python callback to execute in that case, because the output only displays purely in your web browser, and web browsers have no capability to run Python code. The only kind of callbacks that can function are JavaScript callbacks.

There is extensive documentation about running Bokeh server applications in the Running a Bokeh Server chapter of the docs, and extensive documentation about CustomJS callbacks in the JavaScript Callbacks chapter.

bigreddot
  • 33,642
  • 5
  • 69
  • 122