Initiate callback upon page load

Hi,

In bokeh, custom callbacks can be set using a CustomJS object and passing it as the callback argument to an object. I am using “from_py_func” to write those callbacks in Python.This works well.

However, all those callbacks are only executed when the user interacts with the object, such as doing select or range update.

What I need is a way to trigger a callback upon page load, such that it starts without the need

of the user doing anything.

How can this be done? I like to keep things simple for now and achieve this with a standalone bokeh file: no server, no html/javascript hacking.

Thanks

Artur

There's not currently any hook for this. It could probably be a reasonable feature, but there are questions/discussion warranted. E.g. is page load really appropriate? that probably won't work in the notebook, so maybe on some plot initialization step. But then we should try to think of a reasonably simple scheme instead of adding another ad-hoc hook. I'd encourage you to make a feature request issue at Issues · bokeh/bokeh · GitHub

For now, I'd probably recommend replacing the standard FILE template with one that has a little extra JS added to do whatever you want to happen on page load. Otehrwise, it's probably possible to make a custom user model that subclasses Plot and calls a callback on init, but AFAIK this has not been demonstrated.

Bryan

···

On May 3, 2016, at 10:10 AM, Artur Scholz <[email protected]> wrote:

Hi,

In bokeh, custom callbacks can be set using a CustomJS object and passing it as the callback argument to an object. I am using "from_py_func" to write those callbacks in Python.This works well.

However, all those callbacks are only executed when the user interacts with the object, such as doing select or range update.

What I need is a way to trigger a callback upon page load, such that it starts without the need
of the user doing anything.

How can this be done? I like to keep things simple for now and achieve this with a standalone bokeh file: no server, no html/javascript hacking.

Thanks
Artur

--
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/CALqfExaWuAKV9oh2-2AZ10TCZPSOLVeP4OtzbGAdgcS-2Nm3WQ%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks for the hint. Actually a number of use cases come to mind for having a hook at page load. In my case its a 2d world map onto which I want to draw markers for satellite ground tracks, and update their location. But basically any kind of animation would need that.

Your suggestion sounds like the way forward. Unfortunately I have no clue on how to do that. Could you please elaborate more on how to do this.

I am going to post my results when done.

···

On Tuesday, May 3, 2016 at 5:18:24 PM UTC+2, Bryan Van de ven wrote:

There’s not currently any hook for this. It could probably be a reasonable feature, but there are questions/discussion warranted. E.g. is page load really appropriate? that probably won’t work in the notebook, so maybe on some plot initialization step. But then we should try to think of a reasonably simple scheme instead of adding another ad-hoc hook. I’d encourage you to make a feature request issue at https://github.com/bokeh/bokeh/issues

For now, I’d probably recommend replacing the standard FILE template with one that has a little extra JS added to do whatever you want to happen on page load. Otehrwise, it’s probably possible to make a custom user model that subclasses Plot and calls a callback on init, but AFAIK this has not been demonstrated.

Bryan

On May 3, 2016, at 10:10 AM, Artur Scholz [email protected] wrote:

Hi,

In bokeh, custom callbacks can be set using a CustomJS object and passing it as the callback argument to an object. I am using “from_py_func” to write those callbacks in Python.This works well.

However, all those callbacks are only executed when the user interacts with the object, such as doing select or range update.

What I need is a way to trigger a callback upon page load, such that it starts without the need

of the user doing anything.

How can this be done? I like to keep things simple for now and achieve this with a standalone bokeh file: no server, no html/javascript hacking.

Thanks

Artur


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/CALqfExaWuAKV9oh2-2AZ10TCZPSOLVeP4OtzbGAdgcS-2Nm3WQ%40mail.gmail.com.

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

Hi Artur,

Adding more/better docs about the (new) JS API is on my (long) to-do before the next release. In the mean time I am afraid I can only offer examples, and answer questions. Here is an example of a custom user model:

    https://github.com/bokeh/bokeh/blob/master/examples/models/custom.py

Some things to know. On the python side, you'd subclass an existing Bokeh Model, and provide a JS __implementation__ that defines the JS implementation of the Model. BokehJS models are Backbone models, and the code is actually written in coffeescript. I think a custom user extension that makes a subclass that calls a callback on init would look something like this (completely untested):

    class PlotWithCallback(Plot):

        __implementation__ = """
    Plot = require "models/Plot"
    p = require "core/properties"
    
    class PlotWithCallback extends Plot
        type: "PlotWithCallback"

        initialize: (attrs, options) ->
            super()
            @get('callback')?.execute(@)
  
        @define {
            callback: [ p.Any ]
        }

    module.exports =
        Model: PlotWithCallback
    """

        callback = Instance(Callback)

Then you would use it:

    p = PlotWithCallback(...)
    p.callback = CustomJS(...)
    p.add_glyph(...)

Alternatively you might rather have a FigureWithCallback subclass.

Thanks,

Bryan

···

On May 3, 2016, at 2:20 PM, Artur Scholz <[email protected]> wrote:

Thanks for the hint. Actually a number of use cases come to mind for having a hook at page load. In my case its a 2d world map onto which I want to draw markers for satellite ground tracks, and update their location. But basically any kind of *animation* would need that.

Your suggestion sounds like the way forward. Unfortunately I have no clue on how to do that. Could you please elaborate more on how to do this.

I am going to post my results when done.

On Tuesday, May 3, 2016 at 5:18:24 PM UTC+2, Bryan Van de ven wrote:
There's not currently any hook for this. It could probably be a reasonable feature, but there are questions/discussion warranted. E.g. is page load really appropriate? that probably won't work in the notebook, so maybe on some plot initialization step. But then we should try to think of a reasonably simple scheme instead of adding another ad-hoc hook. I'd encourage you to make a feature request issue at Issues · bokeh/bokeh · GitHub

For now, I'd probably recommend replacing the standard FILE template with one that has a little extra JS added to do whatever you want to happen on page load. Otehrwise, it's probably possible to make a custom user model that subclasses Plot and calls a callback on init, but AFAIK this has not been demonstrated.

Bryan

> On May 3, 2016, at 10:10 AM, Artur Scholz <[email protected]> wrote:
>
> Hi,
>
> In bokeh, custom callbacks can be set using a CustomJS object and passing it as the callback argument to an object. I am using "from_py_func" to write those callbacks in Python.This works well.
>
> However, all those callbacks are only executed when the user interacts with the object, such as doing select or range update.
>
> What I need is a way to trigger a callback upon page load, such that it starts without the need
> of the user doing anything.
>
> How can this be done? I like to keep things simple for now and achieve this with a standalone bokeh file: no server, no html/javascript hacking.
>
> Thanks
> Artur
>
>
>
>
>
> --
> 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 bokeh+un...@continuum.io.
> To post to this group, send email to bo...@continuum.io.
> To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/CALqfExaWuAKV9oh2-2AZ10TCZPSOLVeP4OtzbGAdgcS-2Nm3WQ%40mail.gmail.com\.
> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
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/d6fc9f0e-4bbd-41e4-8a32-f2a9aef98879%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Hi Bryan,

thanks for the comments. After having seen the possibilities of using Ajax requests, I know use those for my purpose, instead of callbacks.
http://stackoverflow.com/questions/37083998/flask-bokeh-ajaxdatasource

···

On Wed, May 4, 2016 at 7:24 PM, Bryan Van de Ven [email protected] wrote:

Hi Artur,

Adding more/better docs about the (new) JS API is on my (long) to-do before the next release. In the mean time I am afraid I can only offer examples, and answer questions. Here is an example of a custom user model:

[https://github.com/bokeh/bokeh/blob/master/examples/models/custom.py](https://github.com/bokeh/bokeh/blob/master/examples/models/custom.py)

Some things to know. On the python side, you’d subclass an existing Bokeh Model, and provide a JS implementation that defines the JS implementation of the Model. BokehJS models are Backbone models, and the code is actually written in coffeescript. I think a custom user extension that makes a subclass that calls a callback on init would look something like this (completely untested):

class PlotWithCallback(Plot):



    __implementation__ = """

Plot = require "models/Plot"

p = require "core/properties"



class PlotWithCallback extends Plot

    type: "PlotWithCallback"



    initialize: (attrs, options) ->

        super()

        @get('callback')?.execute(@)



    @define {

        callback: [ p.Any ]

    }



module.exports =

    Model: PlotWithCallback

"""



    callback = Instance(Callback)

Then you would use it:

p = PlotWithCallback(...)

p.callback = CustomJS(...)

p.add_glyph(...)

Alternatively you might rather have a FigureWithCallback subclass.

Thanks,

Bryan

On May 3, 2016, at 2:20 PM, Artur Scholz [email protected] wrote:

Thanks for the hint. Actually a number of use cases come to mind for having a hook at page load. In my case its a 2d world map onto which I want to draw markers for satellite ground tracks, and update their location. But basically any kind of animation would need that.

Your suggestion sounds like the way forward. Unfortunately I have no clue on how to do that. Could you please elaborate more on how to do this.

I am going to post my results when done.

On Tuesday, May 3, 2016 at 5:18:24 PM UTC+2, Bryan Van de ven wrote:

There’s not currently any hook for this. It could probably be a reasonable feature, but there are questions/discussion warranted. E.g. is page load really appropriate? that probably won’t work in the notebook, so maybe on some plot initialization step. But then we should try to think of a reasonably simple scheme instead of adding another ad-hoc hook. I’d encourage you to make a feature request issue at https://github.com/bokeh/bokeh/issues

For now, I’d probably recommend replacing the standard FILE template with one that has a little extra JS added to do whatever you want to happen on page load. Otehrwise, it’s probably possible to make a custom user model that subclasses Plot and calls a callback on init, but AFAIK this has not been demonstrated.

Bryan

On May 3, 2016, at 10:10 AM, Artur Scholz [email protected] wrote:

Hi,

In bokeh, custom callbacks can be set using a CustomJS object and passing it as the callback argument to an object. I am using “from_py_func” to write those callbacks in Python.This works well.

However, all those callbacks are only executed when the user interacts with the object, such as doing select or range update.

What I need is a way to trigger a callback upon page load, such that it starts without the need

of the user doing anything.

How can this be done? I like to keep things simple for now and achieve this with a standalone bokeh file: no server, no html/javascript hacking.

Thanks

Artur

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/CALqfExaWuAKV9oh2-2AZ10TCZPSOLVeP4OtzbGAdgcS-2Nm3WQ%40mail.gmail.com.

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

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/d6fc9f0e-4bbd-41e4-8a32-f2a9aef98879%40continuum.io.

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

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

To unsubscribe from this topic, visit https://groups.google.com/a/continuum.io/d/topic/bokeh/MbDfPa4DNcc/unsubscribe.

To unsubscribe from this group and all its topics, 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/6C047EED-5472-46AC-BDCE-90CF1C87A170%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.