Callbacks Bokeh + Django

I’m trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()

``

)

Is it possible to use python callbacks on embedded charts?

Yes, absolutely. But much more information would be needed to diagnose any possible problems or misconfigurations you might be seeing:

* platform, browser, library versions
* example code to reproduce the problem (both the app and the embedding)
* what exactly did you run (command line options, etc.)
* what actually happened vs what was expected to happen, in detail
* any shell and javascript console output

In general, when asking for help diagnosing problems it's best to err generously on the side of way too much information.

Bryan

···

On Aug 31, 2016, at 2:15 PM, Robbie Pritchard <[email protected]> wrote:

I'm trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()
)

Is it possible to use python callbacks on embedded charts?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/ad4b38fa-99fd-4249-9b45-802b6ba33213%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

platform: OSX 10.11.6

Browser: Chrome 52.0.2743.116

Bokeh: 0.12.1

Django: 1.9.8

Python: 3.5.2

as an example we can use this, which has the same problem as mine.

#onChangeExample.py

from __future__ import print_function
from bokeh.models import MultiSelect, Select, CustomJS, VBox
from bokeh.io import curdoc
from bokeh.client import push_session

def update(attrname, old, new):
    print("""MultiSelect\nOptions: %s\nSelected:%s\n\n
             Select\nOptions:%s\nSelected: %s"""
          % (mscolors.options, mscolors.value, colors.options, colors.value))

# set up select widget
def main():
    colors = Select(title="colors", options=["Red", "Green", "Blue"])
    colors.on_change('value', update)
    colors.callback = CustomJS(code="console.log('Select: ' + cb_obj.get('value'))")

    # set up multiselect widget
    mscolors = MultiSelect(title="Colors", options=["Red", "Green", "Blue"])
    mscolors.on_change('value', update)
    mscolors.callback = CustomJS(code="console.log('MultiSelect: ' + cb_obj.get('value'))")

    curdoc().add_root(VBox(colors, mscolors))

    session = push_session(curdoc())

    return session

``

then in my views.py in Django

import …/pathto/…/onChangeExample as onChange
the_script = autoload_server(model=None, session_id=onChange.main().id)

return render(request, "simple_chart.html", {'the_script': the_script })

``


then in my simple_chart.html

Experiment with Bokeh
{{ the_script| safe }}

``


IN TWO TERMINAL WINDOWS

running(bokeh): bokeh serve --allow-websocket-origin=127.0.0.1:8000

running(python): python3 manage.py run server

WHAT HAPPENED

The graph shows. The customJS callback is working and I am getting prints in my js inspector. Yet I am getting no prints on the shell of my bokeh server

WHAT I EXPECT TO HAPPEN

When I run the graph using

bokeh serve --show onChangeExample.py --allow-websocket-origin=127.0.0.1:8000

``

the graph shows. I get prints in the js inspector, and i get prints on the shell of my bokeh server

Attached is the terminal output

···

On Wednesday, August 31, 2016 at 2:15:58 PM UTC-5, Robbie Pritchard wrote:

I’m trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()

``

)

Is it possible to use python callbacks on embedded charts?

Hi Robbie,

Is there a particular reason you are wanting to use an "empty" server and then use push_session to that? We definitely recommend running apps directly on the server (ala "bokeh serve app.py"), especially for serious deployments. You can still embed a a session from an app run that with autoload_server. (In fact, I had assumed that is what you meant! Also why details are important to share.)

If you need to do some kind of per-session customization, that is also now possible to do that by passing HTTP request arguments:

  https://github.com/bokeh/bokeh/pull/4912

This PR is in master, and the latest dev build, and will be in the upcoming 0.12.2 release. Dev build install instructions are here:

  http://bokeh.pydata.org/en/latest/docs/installation.html#developer-builds

I'd definitely strongly encourage you to pursue this route before using bokeh.client, push_session, etc directly from Django. That approach has a number of drawbacks compared to running "bokeh serve app.py". The session customization use-case was pretty much the only reason to consider using bokeh.client, but with the HTTP requests arguments PR above, there should be almost no reason to.

Thanks,

Bryan

···

On Aug 31, 2016, at 4:14 PM, Robbie Pritchard <[email protected]> wrote:

Attached is the terminal output

On Wednesday, August 31, 2016 at 2:15:58 PM UTC-5, Robbie Pritchard wrote:
I'm trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()
)

Is it possible to use python callbacks on embedded charts?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2504a3ed-778a-40b4-a602-2d359a32f907%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
<Screen Shot 2016-08-31 at 4.12.51 PM.png><Screen Shot 2016-08-31 at 4.13.03 PM.png>

To add something concrete, to embed an app from a running server using autoload_server, you would do, e.g.

  script = autoload_server(model=None,
                                 app_path="/apps/slider",
                                 url="https://demo.bokehplots.com")

Thanks,

Bryan

···

On Aug 31, 2016, at 4:31 PM, Bryan Van de Ven <[email protected]> wrote:

Hi Robbie,

Is there a particular reason you are wanting to use an "empty" server and then use push_session to that? We definitely recommend running apps directly on the server (ala "bokeh serve app.py"), especially for serious deployments. You can still embed a a session from an app run that with autoload_server. (In fact, I had assumed that is what you meant! Also why details are important to share.)

If you need to do some kind of per-session customization, that is also now possible to do that by passing HTTP request arguments:

  https://github.com/bokeh/bokeh/pull/4912

This PR is in master, and the latest dev build, and will be in the upcoming 0.12.2 release. Dev build install instructions are here:

  http://bokeh.pydata.org/en/latest/docs/installation.html#developer-builds

I'd definitely strongly encourage you to pursue this route before using bokeh.client, push_session, etc directly from Django. That approach has a number of drawbacks compared to running "bokeh serve app.py". The session customization use-case was pretty much the only reason to consider using bokeh.client, but with the HTTP requests arguments PR above, there should be almost no reason to.

Thanks,

Bryan

On Aug 31, 2016, at 4:14 PM, Robbie Pritchard <[email protected]> wrote:

Attached is the terminal output

On Wednesday, August 31, 2016 at 2:15:58 PM UTC-5, Robbie Pritchard wrote:
I'm trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()
)

Is it possible to use python callbacks on embedded charts?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2504a3ed-778a-40b4-a602-2d359a32f907%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.
<Screen Shot 2016-08-31 at 4.12.51 PM.png><Screen Shot 2016-08-31 at 4.13.03 PM.png>

In Django:
the_script = autoload_server(model=None,app_path='/emptydetails_graph',url="http://127.0.0.1:5006/")


In Terminal:
rpritchard$ bokeh serve emptydetails_graph.py --address=127.0.0.1 --host='*'



and now the graph isn’t showing.

···

On Wednesday, August 31, 2016 at 4:33:52 PM UTC-5, Bryan Van de ven wrote:

To add something concrete, to embed an app from a running server using autoload_server, you would do, e.g.

    script = autoload_server(model=None,
                             app_path="/apps/slider",
                             url="[https://demo.bokehplots.com](https://demo.bokehplots.com)")

Thanks,

Bryan

On Aug 31, 2016, at 4:31 PM, Bryan Van de Ven [email protected] wrote:

Hi Robbie,

Is there a particular reason you are wanting to use an “empty” server and then use push_session to that? We definitely recommend running apps directly on the server (ala “bokeh serve app.py”), especially for serious deployments. You can still embed a a session from an app run that with autoload_server. (In fact, I had assumed that is what you meant! Also why details are important to share.)

If you need to do some kind of per-session customization, that is also now possible to do that by passing HTTP request arguments:

    [https://github.com/bokeh/bokeh/pull/4912](https://github.com/bokeh/bokeh/pull/4912)

This PR is in master, and the latest dev build, and will be in the upcoming 0.12.2 release. Dev build install instructions are here:

    [http://bokeh.pydata.org/en/latest/docs/installation.html#developer-builds](http://bokeh.pydata.org/en/latest/docs/installation.html#developer-builds)

I’d definitely strongly encourage you to pursue this route before using bokeh.client, push_session, etc directly from Django. That approach has a number of drawbacks compared to running “bokeh serve app.py”. The session customization use-case was pretty much the only reason to consider using bokeh.client, but with the HTTP requests arguments PR above, there should be almost no reason to.

Thanks,

Bryan

On Aug 31, 2016, at 4:14 PM, Robbie Pritchard [email protected] wrote:

Attached is the terminal output

On Wednesday, August 31, 2016 at 2:15:58 PM UTC-5, Robbie Pritchard wrote:

I’m trying to use callbacks from an bokeh chart embedded into django. The callbacks will need to be able to run python code, explicitly pandas. While the callbacks are working with the show method. They are not working with the embedded chart ( created from
autoload_server()

)

Is it possible to use python callbacks on embedded charts?


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2504a3ed-778a-40b4-a602-2d359a32f907%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

<Screen Shot 2016-08-31 at 4.12.51 PM.png><Screen Shot 2016-08-31 at 4.13.03 PM.png>

The issue we had with running individual apps was scalability. We will be running many apps at the same time. bokeh serve app1.py app2.py app3.py … appn.py seems excessive.

In what way, exactly? That is how demo.bokehplots.com is deployed, for example.

Do you mean that some of the apps use alot of compute, individually? Then they probably need to go on separate machines/VMs anyway (Bokeh can't magically make compute burdens smaller than they are). Do you mean the list of apps is dynamic or changes alot? Then you might be interested in this recent ML thread where a user figured out how to spin up bokeh serve apps programmatically:

  https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/LYmjTXzX43E

Do you mean scalable in terms of users? Then "bokeh serve app.py" is expressly more scalable. To gain more capacity just run more behind a load balancer as demonstrated in the users guide.

Bryan

···

On Aug 31, 2016, at 5:17 PM, Robbie Pritchard <[email protected]> wrote:

The issue we had with running individual apps was scalability. We will be running many apps at the same time. bokeh serve app1.py app2.py app3.py ... appn.py seems excessive.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1656ea75-20f6-4c29-bd44-119a32d97f2a%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Yes, sorry about the confusion. The list of apps is dynamic/ changes a lot. That ML thread look great, and should solve that problem.

Thank you!

···

On Wednesday, August 31, 2016 at 5:29:42 PM UTC-5, Bryan Van de ven wrote:

In what way, exactly? That is how demo.bokehplots.com is deployed, for example.

Do you mean that some of the apps use alot of compute, individually? Then they probably need to go on separate machines/VMs anyway (Bokeh can’t magically make compute burdens smaller than they are). Do you mean the list of apps is dynamic or changes alot? Then you might be interested in this recent ML thread where a user figured out how to spin up bokeh serve apps programmatically:

    [https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/LYmjTXzX43E](https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/LYmjTXzX43E)

Do you mean scalable in terms of users? Then “bokeh serve app.py” is expressly more scalable. To gain more capacity just run more behind a load balancer as demonstrated in the users guide.

Bryan

On Aug 31, 2016, at 5:17 PM, Robbie Pritchard [email protected] wrote:

The issue we had with running individual apps was scalability. We will be running many apps at the same time. bokeh serve app1.py app2.py app3.py … appn.py seems excessive.


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/1656ea75-20f6-4c29-bd44-119a32d97f2a%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.