0

I'm trying to figure out how to launch a Bokeh server from clicking a button on a webpage. My current approach is inspired from this post. The relevant code is below.

#rendering the HTML page which has the button
@app.route('/json')
def json():
    return render_template('json.html')

#background process happening without any refreshing
@app.route('/background_process_test')
def background_process_test():
    // launch bokeh server
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type=text/javascript>
        $(function() {
          $('a#test').bind('click', function() {
            $.getJSON('/background_process_test',
                function(data) {
              //do nothing
            });
            return false;
          });
        });
</script>


//button
<div class='container'>
    <h3>Test</h3>
        <form>
            <a href=# id=test><button class='btn btn-default'>Test</button></a>
        </form>

</div>

The end goal is to have the button launch the bokeh server with the app running, and redirect to the webpage containing the app. Any thoughts of how to do this, or different approaches I should consider are most welcome.

c3y
  • 39
  • 5
  • Being frank, this is not a good idea. Bokeh servers listen on a specific port so by default this would fall over as soon as a second connection comes in an a bokeh server tries to start on an already used port. You could have the bokeh server start on a random port but then you have to parse log output to get the actual port used (fragile), have resource leak issues (how do you know when to shut a server down?) and possibly network issues (do you have a firewall or proxy that only leaves a few ports open?) The bokeh server is intended to handle multiple connections. Start one of them up front. – bigreddot Feb 08 '20 at 16:08
  • Thanks for the advice! Are you aware of a way to add an app to a running bokeh server? – c3y Feb 08 '20 at 21:48
  • Not possible with the standard `bokeh serve` application. See https://discourse.bokeh.org/t/how-to-add-more-applications-to-a-running-bokeh-server/2942/7 – bigreddot Feb 09 '20 at 19:10

0 Answers0