Bokeh server and on.click (on.change) doing nothing
<p>I am trying to get Bokeh server to print out, however all I get is an instance running on <a href="http://localhost:5006/?bokeh-session-id=default" rel="nofollow">http://localhost:5006/?bokeh-session-id=default</a> with the radio buttons. When I click the buttons nothing happens. Is there something I am missing?</p>

<pre><code>from bokeh.models.widgets import RadioButtonGroup
from bokeh.plotting import figure, show, output_server


def my_radio_handler():
    print 'Radio button option selected.'


radio_button_group = RadioButtonGroup(
        labels=["Option 1", "Option 2", "Option 3"], active=0)

radio_button_group.on_click(my_radio_handler)

output_server()

show(radio_button_group)
</code></pre>

<p>The answer above shows how this can properly be accomplished with <code>bokeh.client</code> and <code>push_session</code> and <code>session.loop_until_closed</code>.</p>

<p>I'd like to add a few more comments for context. (I am a core developer of the Bokeh project)</p>

<p>There are two general ways that Bokeh applications can run:</p>

<h2>Directly In the Server</h2>

<p>These are scripts that are run something like:</p>

<pre><code>bokeh serve --show my_app.py
</code></pre>

<p>In this case, the code, the objects, all the callbacks, etc. are running <em>in the bokeh server itself.</em> The situation looks like this:</p>

<pre><code>                          browser &lt;---&gt; Bokeh Server
</code></pre>

<p>This is the method I would always recommend first. It takes the least amount of code, is the simplest to deploy, can be scaled out, uses less network traffic, and is more robust. </p>

<h2>In a Separate Python Process</h2>

<p>It's also possible to create the app and run callbacks in a separate process, using <code>bokeh.client</code>. Then the situation looks like this:</p>

<pre><code>               browser &lt;---&gt; Bokeh Server &lt;---&gt; another python process
</code></pre>

<p>Then the Bokeh server really just become a middleman, relaying messages between the browser and your python process. This has disadvantages: </p>

<ul>
<li>doubles the network traffic (for the new python process, unavoidable by definition)</li>
<li>takes more code to write (all the <code>session</code> stuff not need in "Server Apps")</li>
<li>requires the python process to block indefinitely to service the callbacks (have to call <code>session.loop_until_closed</code>)</li>
</ul>

<p>In the past, there were specific use-cases where using <code>bokeh.client</code> was necessary, for example: being able to customize app sessions per-use. But now that HTML request arguments are available to "Server Apps" that can be accomplished without <code>bokeh.client</code>. I would say there are now fewer reasons to reach for the <code>bokeh.client</code> approach. For this reason <strong><em>I always recommend the <code>bokeh serve my_app.py</code> method as the first, best way to use the Bokeh server</em></strong>.</p>

<hr>

<p>But, getting back to the question at hand: So what happens in the <em>Separate Python Process</em> scenario, if you forget to call <code>session.loop_until_closed</code>? Well the python process (the one that has your callbacks!) finishes, and the process terminates. Then there is nothing left to actually run the callbacks. </p>

<p>Well, this is essentially exactly the situation with <code>output_server</code>. It does the "first half" of the session setup, loading the objects in to the server, but then your python script that calls <code>output_server</code> finishes, and nothing is left to execute any callbacks. <code>output_server</code> is basically still around due to accidents of history, but I would say it is not very useful at all. At best, it can load apps with no callbacks into a Bokeh server, but then why would you need a Bokeh server except to connect web apps to real python callbacks?</p>

<p>There is currently (as of release <code>0.12.2</code>) an open issue discussing deprecating <code>output_server</code> for this reason:</p>

<p><a href="https://github.com/bokeh/bokeh/issues/5154" rel="nofollow">https://github.com/bokeh/bokeh/issues/5154</a></p>

<p>TLDR; <strong>I would not recommend using <code>output_server</code> for any reason at this point.</strong></p>

python bokeh