Call javascript inside a python function

Thank you for reading. I googled a lot but cannot find an answer, so I might try my luck here.

I am running a bokeh server. When a widget (say, a button) is clicked, a python function is triggered. However, I want to run some javascript code at the same time. Is it possible? Thanks for any advice.

Try adding a seperate CustomJS callback:
bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html

···

On 8/4/16 1:33 AM, Bill wrote:

    Thank you for reading. I googled a lot but cannot

find an answer, so I might try my luck here.

      I am running a bokeh server. When a widget (say, a button)

is clicked, a python function is triggered. However, I want to
run some javascript code at the same time. Is it possible?
Thanks for any advice.

  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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

I would only keep in mind: CustomJS callbacks will execute in the browser, essentially immediately, while any python callback will execute in a Bokeh server after a network protocol exchange. So "same time" has to be interpreted with some looseness. If you have two unrelated tasks, things should be fine. If you need to enforce some ordering or synchronization between the two types of callbacks, that's probably not possible (except that the CustomJS will "probably" always execute first, but no guarantees there either).

Thanks,

Bryan

···

On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]> wrote:

Try adding a seperate CustomJS callback: bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html

On 8/4/16 1:33 AM, Bill wrote:

Thank you for reading. I googled a lot but cannot find an answer, so I might try my luck here.

I am running a bokeh server. When a widget (say, a button) is clicked, a python function is triggered. However, I want to run some javascript code at the same time. Is it possible? Thanks for any advice.
--
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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Sarah Bird
Developer, Bokeh

--
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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thank you both for the help. If I understand, I can use .on_change method to call python function, and .callback attribute to call CustomJS?

Actually I wanted to do something a little different. I am trying to get the width and height of a plot using the following JS. I found a solution online which is to attach this JS to x_range.callback. However, I am wondering if there is a way to call this JS directly without needing to change x range first.

Hope this make sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

new_data[‘height’] = [plot.plot_canvas.frame.get(‘height’)];

new_data[‘width’] = [plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

if (typeof throttle != ‘undefined’ && throttle != null) {

clearTimeout(throttle);

}

throttle = setTimeout(update_dims, 100, “replace”);

“”"

dims = ColumnDataSource(dict(width=[plot_width], height=[plot_height] ))

fig.x_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))

···

On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de ven wrote:

I would only keep in mind: CustomJS callbacks will execute in the browser, essentially immediately, while any python callback will execute in a Bokeh server after a network protocol exchange. So “same time” has to be interpreted with some looseness. If you have two unrelated tasks, things should be fine. If you need to enforce some ordering or synchronization between the two types of callbacks, that’s probably not possible (except that the CustomJS will “probably” always execute first, but no guarantees there either).

Thanks,

Bryan

On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum [email protected] wrote:

Try adding a seperate CustomJS callback: bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html

On 8/4/16 1:33 AM, Bill wrote:

Thank you for reading. I googled a lot but cannot find an answer, so I might try my luck here.

I am running a bokeh server. When a widget (say, a button) is clicked, a python function is triggered. However, I want to run some javascript code at the same time. Is it possible? Thanks for any advice.


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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io.

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


Sarah Bird

Developer, Bokeh


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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io.

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

Bokeh in general needs events to fire actions. The server will
accept “periodic call backs” and
from that you should be able to read the wi dth and
height.

If you’re just putting some JS on your page to
inspect you r
bokeh items you can use the
Bokeh.index to find your plot and start
inspecting it.

                                So I think you

cou ld
build a function like that that
uses Bokeh.index to get at your bokeh object s
and then c all
it at will.

···

On 8/4/16 8:35 AM, Bill wrote:

      Thank you both for the help. If I

understand, I can use .on_change method to call python
function, and .callback attribute to call CustomJS?

      Actually I wanted

to do something a little different. I am trying to get the
width and height of a plot using the following JS. I found a
solution online which is to attach this JS to
x_range.callback. However, I am wondering if there is a way to
call this JS directly without needing to change x range first.

      Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

        new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

        new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

        if (typeof throttle != 'undefined' && throttle !=

null) {

clearTimeout(throttle);

}

throttle = setTimeout(update_dims, 100, “replace”);

“”"

          dims = ColumnDataSource(dict(width=[plot_width],

height=[plot_height] ))

          fig.x_range.callback = CustomJS(code=dims_jscode,

args=dict(plot=fig, dims=dims))

    On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de

ven wrote:

      I would

only keep in mind: CustomJS callbacks will execute in the
browser, essentially immediately, while any python callback
will execute in a Bokeh server after a network protocol
exchange. So “same time” has to be interpreted with some
looseness. If you have two unrelated tasks, things should be
fine. If you need to enforce some ordering or synchronization
between the two types of callbacks, that’s probably not
possible (except that the CustomJS will “probably” always
execute first, but no guarantees there either).

      Thanks,




      Bryan





      > On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]          >

wrote:

      >

      > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


      >

      > On 8/4/16 1:33 AM, Bill wrote:


      >> Thank you for reading. I googled a lot but cannot

find an answer, so I might try my luck here.

      >>

      >> I am running a bokeh server. When a widget (say, a

button) is clicked, a python function is triggered. However, I
want to run some javascript code at the same time. Is it
possible? Thanks for any advice.

      >> --

      >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)          .


      >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)          .


      >

      > --

      > Sarah Bird


      > Developer, Bokeh

      >

      >  


      >

      >

      > --

      > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)          .


      > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

Thank you for the reply. Do you mean “curdoc().add_periodic_callback”? I though it only calls python function but not JS, is it?

···

On Friday, August 5, 2016 at 8:59:41 PM UTC+8, Sarah Bird wrote:

Bokeh in general needs events to fire actions. The server will
accept “periodic call backs” and
from that you should be able to read the wi dth and
height.

If you’re just putting some JS on your page to
inspect you r
bokeh items you can use the
Bokeh.index to find your plot and start
inspecting it.

                                So I think you

cou ld
build a function like that that
uses Bokeh.index to get at your bokeh object s
and then c all
it at will.

On 8/4/16 8:35 AM, Bill wrote:

      Thank you both for the help. If I

understand, I can use .on_change method to call python
function, and .callback attribute to call CustomJS?

      Actually I wanted

to do something a little different. I am trying to get the
width and height of a plot using the following JS. I found a
solution online which is to attach this JS to
x_range.callback. However, I am wondering if there is a way to
call this JS directly without needing to change x range first.

      Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

        new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

        new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

        if (typeof throttle != 'undefined' && throttle !=

null) {

clearTimeout(throttle);

}

throttle = setTimeout(update_dims, 100, “replace”);

“”"

dims = ColumnDataSource(dict(width=[ plot_width],
height=[plot_height] ))

          fig.x_range.callback = CustomJS(code=dims_jscode,

args=dict(plot=fig, dims=dims))

    On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de > > ven wrote:
      I would

only keep in mind: CustomJS callbacks will execute in the
browser, essentially immediately, while any python callback
will execute in a Bokeh server after a network protocol
exchange. So “same time” has to be interpreted with some
looseness. If you have two unrelated tasks, things should be
fine. If you need to enforce some ordering or synchronization
between the two types of callbacks, that’s probably not
possible (except that the CustomJS will “probably” always
execute first, but no guarantees there either).

      Thanks,




      Bryan





      > On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]          > > > > wrote:


      >

      > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


      >

      > On 8/4/16 1:33 AM, Bill wrote:


      >> Thank you for reading. I googled a lot but cannot

find an answer, so I might try my luck here.

      >>

      >> I am running a bokeh server. When a widget (say, a

button) is clicked, a python function is triggered. However, I
want to run some javascript code at the same time. Is it
possible? Thanks for any advice.

      >> --

      >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)          .


      >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)          .


      >

      > --

      > Sarah Bird


      > Developer, Bokeh

      >

      >  


      >

      >

      > --

      > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)          .


      > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" style="width:150px;min-height:30px" height="30px" width="150px">
    ](http://continuum.io)

Yes, it does. It depends on what you’re trying to do. I was trying to draw the dis tinction that we don’t have
anything on the JS side that will just run code without a trigger, so you have to write it yourself.

···

On 8/6/16 7:29 AM, Bill wrote:

    Thank you for the reply. Do you mean

“curdoc().add_periodic_callback”? I though it only calls python
function but not JS, is it?

    On Friday, August 5, 2016 at 8:59:41 PM UTC+8, Sarah Bird wrote:

Bokeh in general needs
events to fire actions.
The server will accept “periodic callbacks” and from that you should be able to read the width and height.

If you’re just
putting some JS on your page to inspect you r bokeh
items you can use the
Bokeh.index to find
your plot and start inspecting
it.

                                        So I

think you cou ld
build a function like that
that uses Bokeh .index
to get at your bokeh
objects and then c all it at
will.

On 8/4/16 8:35 AM, Bill wrote:

              Thank

you both for the help. If I understand, I can use
.on_change method to call python function, and
.callback attribute to call CustomJS?

              Actually I

wanted to do something a little different. I am trying
to get the width and height of a plot using the
following JS. I found a solution online which is to
attach this JS to x_range.callback. However, I am
wondering if there is a way to call this JS directly
without needing to change x range first.

              Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

                new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

                new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

                if (typeof throttle != 'undefined' &&

throttle != null) {

clearTimeout(throttle);

}

                throttle = setTimeout(update_dims, 100,

“replace”);

“”"

dims = ColumnDataSource(dict(width=[ plot_width],
height=[plot_height] ))

                  fig.x_range.callback =

CustomJS(code=dims_jscode, args=dict(plot=fig,
dims=dims))

            On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan

Van de ven wrote:

              I would only keep in mind:

CustomJS callbacks will execute in the browser,
essentially immediately, while any python callback
will execute in a Bokeh server after a network
protocol exchange. So “same time” has to be
interpreted with some looseness. If you have two
unrelated tasks, things should be fine. If you need to
enforce some ordering or synchronization between the
two types of callbacks, that’s probably not possible
(except that the CustomJS will “probably” always
execute first, but no guarantees there either).

              Thanks,



              Bryan





              > On Aug 4, 2016, at 8:05 AM, Sarah Bird -

Continuum <[email protected] >
wrote:

              >

              > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


              >

              > On 8/4/16 1:33 AM, Bill wrote:

              >> Thank you for reading. I googled a lot but

cannot find an answer, so I might try my luck here.

              >>

              >> I am running a bokeh server. When a widget

(say, a button) is clicked, a python function is
triggered. However, I want to run some javascript code
at the same time. Is it possible? Thanks for any
advice.

              >> --

              >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)                  .


              >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)                  .


              >

              > --

              > Sarah Bird

              > Developer, Bokeh

              >

              >  

              >

              >

              > --

              > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)                  .


              > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

            [ ![Continuum
                Analytics](https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000) ](http://continuum.io)

  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/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

Got it. thank you

···

On Sun, Aug 7, 2016 at 2:15 AM, Sarah Bird - Continuum [email protected] wrote:

Yes, it does. It depends on what you’re trying to do. I was trying to draw the dis tinction that we don’t have
anything on the JS side that will just run code without a trigger, so you have to write it yourself.

On 8/6/16 7:29 AM, Bill wrote:

Bokeh in general needs
events to fire actions.
The server will accept “periodic callbacks” and from that you should be able to read the width and height.

If you’re just
putting some JS on your page to inspect you r bokeh
items you can use the
Bokeh.index to find
your plot and start inspecting
it.

                                        So I

think you cou ld
build a function like that
that uses Bokeh .index
to get at your bokeh
objects and then c all it at
will.

On 8/4/16 8:35 AM, Bill wrote:

              Thank

you both for the help. If I understand, I can use
.on_change method to call python function, and
.callback attribute to call CustomJS?

              Actually I

wanted to do something a little different. I am trying
to get the width and height of a plot using the
following JS. I found a solution online which is to
attach this JS to x_range.callback. However, I am
wondering if there is a way to call this JS directly
without needing to change x range first.

              Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

                new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

                new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

                if (typeof throttle != 'undefined' &&

throttle != null) {

clearTimeout(throttle);

}

                throttle = setTimeout(update_dims, 100,

“replace”);

“”"

dims = ColumnDataSource(dict(width=[p lot_width],
height=[plot_height] ))

                  fig.x_range.callback =

CustomJS(code=dims_jscode, args=dict(plot=fig,
dims=dims))

            On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan

Van de ven wrote:

              I would only keep in mind:

CustomJS callbacks will execute in the browser,
essentially immediately, while any python callback
will execute in a Bokeh server after a network
protocol exchange. So “same time” has to be
interpreted with some looseness. If you have two
unrelated tasks, things should be fine. If you need to
enforce some ordering or synchronization between the
two types of callbacks, that’s probably not possible
(except that the CustomJS will “probably” always
execute first, but no guarantees there either).

              Thanks,



              Bryan





              > On Aug 4, 2016, at 8:05 AM, Sarah Bird -

Continuum <[email protected] >
wrote:

              >

              > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


              >

              > On 8/4/16 1:33 AM, Bill wrote:

              >> Thank you for reading. I googled a lot but

cannot find an answer, so I might try my luck here.

              >>

              >> I am running a bokeh server. When a widget

(say, a button) is clicked, a python function is
triggered. However, I want to run some javascript code
at the same time. Is it possible? Thanks for any
advice.

              >> --

              >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)                  .


              >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)                  .


              >

              > --

              > Sarah Bird

              > Developer, Bokeh

              >

              >  

              >

              >

              > --

              > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)                  .


              > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

            [ ![Continuum
                Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png) ](http://continuum.io)
    Thank you for the reply. Do you mean

“curdoc().add_periodic_ callback”? I though it only calls python
function but not JS, is it?

    On Friday, August 5, 2016 at 8:59:41 PM UTC+8, Sarah Bird wrote:

  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/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

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/8a5ed8f6-954f-d3f4-8858-de26822d57cc%40continuum.io.

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

Sarah, thank you for your help. But sorry for being slow. I might misunderstand your comment. I just tried curdoc().add_periodic_callback(CustomJS(…)) but it gives me error ‘CustomJS’ object is not callable. That was my concern since CustomJS is not callable. Is there another way to call JS, or you actually meant that it is no possible to call JS in add_periodic_callback. Thank you for your patience.

···

On Sun, Aug 7, 2016 at 2:15 AM, Sarah Bird - Continuum [email protected] wrote:

Yes, it does. It depends on what you’re trying to do. I was trying to draw the dis tinction that we don’t have
anything on the JS side that will just run code without a trigger, so you have to write it yourself.

On 8/6/16 7:29 AM, Bill wrote:

Bokeh in general needs
events to fire actions.
The server will accept “periodic callbacks” and from that you should be able to read the width and height.

If you’re just
putting some JS on your page to inspect you r bokeh
items you can use the
Bokeh.index to find
your plot and start inspecting
it.

                                        So I

think you cou ld
build a function like that
that uses Bokeh .index
to get at your bokeh
objects and then c all it at
will.

On 8/4/16 8:35 AM, Bill wrote:

              Thank

you both for the help. If I understand, I can use
.on_change method to call python function, and
.callback attribute to call CustomJS?

              Actually I

wanted to do something a little different. I am trying
to get the width and height of a plot using the
following JS. I found a solution online which is to
attach this JS to x_range.callback. However, I am
wondering if there is a way to call this JS directly
without needing to change x range first.

              Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

                new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

                new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

                if (typeof throttle != 'undefined' &&

throttle != null) {

clearTimeout(throttle);

}

                throttle = setTimeout(update_dims, 100,

“replace”);

“”"

dims = ColumnDataSource(dict(width=[p lot_width],
height=[plot_height] ))

                  fig.x_range.callback =

CustomJS(code=dims_jscode, args=dict(plot=fig,
dims=dims))

            On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan

Van de ven wrote:

              I would only keep in mind:

CustomJS callbacks will execute in the browser,
essentially immediately, while any python callback
will execute in a Bokeh server after a network
protocol exchange. So “same time” has to be
interpreted with some looseness. If you have two
unrelated tasks, things should be fine. If you need to
enforce some ordering or synchronization between the
two types of callbacks, that’s probably not possible
(except that the CustomJS will “probably” always
execute first, but no guarantees there either).

              Thanks,



              Bryan





              > On Aug 4, 2016, at 8:05 AM, Sarah Bird -

Continuum <[email protected] >
wrote:

              >

              > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


              >

              > On 8/4/16 1:33 AM, Bill wrote:

              >> Thank you for reading. I googled a lot but

cannot find an answer, so I might try my luck here.

              >>

              >> I am running a bokeh server. When a widget

(say, a button) is clicked, a python function is
triggered. However, I want to run some javascript code
at the same time. Is it possible? Thanks for any
advice.

              >> --

              >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)                  .


              >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)                  .


              >

              > --

              > Sarah Bird

              > Developer, Bokeh

              >

              >  

              >

              >

              > --

              > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)                  .


              > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

            [ ![Continuum
                Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png) ](http://continuum.io)
    Thank you for the reply. Do you mean

“curdoc().add_periodic_ callback”? I though it only calls python
function but not JS, is it?

    On Friday, August 5, 2016 at 8:59:41 PM UTC+8, Sarah Bird wrote:

  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/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

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/8a5ed8f6-954f-d3f4-8858-de26822d57cc%40continuum.io.

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

You cannot use JS with add_periodic_callback.

You can only use a python function.

···

It is only a server-side feature.

Sarah Bird
[email protected]

On Aug 6, 2016, at 9:30 PM, F. Bill Shi [email protected] wrote:

Sarah, thank you for your help. But sorry for being slow. I might misunderstand your comment. I just tried curdoc().add_periodic_callback(CustomJS(…)) but it gives me error ‘CustomJS’ object is not callable. That was my concern since CustomJS is not callable. Is there another way to call JS, or you actually meant that it is no possible to call JS in add_periodic_callback. Thank you for your patience.

On Sun, Aug 7, 2016 at 2:15 AM, Sarah Bird - Continuum [email protected] wrote:

Yes, it does. It depends on what you’re trying to do. I was trying to draw the dis tinction that we don’t have
anything on the JS side that will just run code without a trigger, so you have to write it yourself.

On 8/6/16 7:29 AM, Bill wrote:

Bokeh in general needs
events to fire actions.
The server will accept “periodic callbacks” and from that you should be able to read the width and height.

If you’re just
putting some JS on your page to inspect you r bokeh
items you can use the
Bokeh.index to find
your plot and start inspecting
it.

                                        So I

think you cou ld
build a function like that
that uses Bokeh .index
to get at your bokeh
objects and then c all it at
will.

On 8/4/16 8:35 AM, Bill wrote:

              Thank

you both for the help. If I understand, I can use
.on_change method to call python function, and
.callback attribute to call CustomJS?

              Actually I

wanted to do something a little different. I am trying
to get the width and height of a plot using the
following JS. I found a solution online which is to
attach this JS to x_range.callback. However, I am
wondering if there is a way to call this JS directly
without needing to change x range first.

              Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

                new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

                new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

                if (typeof throttle != 'undefined' &&

throttle != null) {

clearTimeout(throttle);

}

                throttle = setTimeout(update_dims, 100,

“replace”);

“”"

dims = ColumnDataSource(dict(width=[p lot_width],
height=[plot_height] ))

                  fig.x_range.callback =

CustomJS(code=dims_jscode, args=dict(plot=fig,
dims=dims))

            On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan

Van de ven wrote:

              I would only keep in mind:

CustomJS callbacks will execute in the browser,
essentially immediately, while any python callback
will execute in a Bokeh server after a network
protocol exchange. So “same time” has to be
interpreted with some looseness. If you have two
unrelated tasks, things should be fine. If you need to
enforce some ordering or synchronization between the
two types of callbacks, that’s probably not possible
(except that the CustomJS will “probably” always
execute first, but no guarantees there either).

              Thanks,



              Bryan





              > On Aug 4, 2016, at 8:05 AM, Sarah Bird -

Continuum <[email protected] >
wrote:

              >

              > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


              >

              > On 8/4/16 1:33 AM, Bill wrote:

              >> Thank you for reading. I googled a lot but

cannot find an answer, so I might try my luck here.

              >>

              >> I am running a bokeh server. When a widget

(say, a button) is clicked, a python function is
triggered. However, I want to run some javascript code
at the same time. Is it possible? Thanks for any
advice.

              >> --

              >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)                  .


              >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)                  .


              >

              > --

              > Sarah Bird

              > Developer, Bokeh

              >

              >  

              >

              >

              > --

              > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)                  .


              > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

            [ ![Continuum
                Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png) ](http://continuum.io)
    Thank you for the reply. Do you mean

“curdoc().add_periodic_ callback”? I though it only calls python
function but not JS, is it?

    On Friday, August 5, 2016 at 8:59:41 PM UTC+8, Sarah Bird wrote:

  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/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/0912ce7c-f9ab-4c33-ba36-c1c9e516c573%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      ![Continuum Analytics](http://docs.continuum.io/_static/img/ContinuumWordmark.png)
    ](http://continuum.io)

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/8a5ed8f6-954f-d3f4-8858-de26822d57cc%40continuum.io.

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/CALDtjBSEuzXLXy73a%3DAvGkOec_%3DhnwmQRrAJTSZRFEM9nZp1Ug%40mail.gmail.com.

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

From the docs I understand that “CustomJS callbacks can be attached to property change events on any Bokeh model”. Are Div and PreText considered models?

Since PreText has a ‘text’ attribute, Should be able to call pretext_object.on_change(‘text’, callback)?

I tried the following to no avail:

results = PreText(text=‘test’)

toggle_pulse = dict()

toggle_pulse = CustomJS(args=toggle_pulse, code=‘’’
var this_id = cb_obj.attributes[‘id’];
var input_div = document.getElementById(this_id);
var target_div = $(input_div).parent().parent().siblings()[0];
target_div.style.display = ‘none’;
‘’')

#(another set of functions calculates results and updates the pretext results object)

results.on_change(‘text’, toggle_pulse)

``

``

Also, what’s protocol on responding to old posts? Is there a ‘too old’ where the latest Bokeh version is too old to make the original post relevant, or is it better for searching purposes to use related threads whenever possible?

Thanks!

Dan

···

On Friday, August 5, 2016 at 5:59:41 AM UTC-7, Sarah Bird wrote:

Bokeh in general needs events to fire actions. The server will
accept “periodic call backs” and
from that you should be able to read the wi dth and
height.

If you’re just putting some JS on your page to
inspect you r
bokeh items you can use the
Bokeh.index to find your plot and start
inspecting it.

                                So I think you

cou ld
build a function like that that
uses Bokeh.index to get at your bokeh object s
and then c all
it at will.

On 8/4/16 8:35 AM, Bill wrote:

      Thank you both for the help. If I

understand, I can use .on_change method to call python
function, and .callback attribute to call CustomJS?

      Actually I wanted

to do something a little different. I am trying to get the
width and height of a plot using the following JS. I found a
solution online which is to attach this JS to
x_range.callback. However, I am wondering if there is a way to
call this JS directly without needing to change x range first.

      Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

        new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

        new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

        if (typeof throttle != 'undefined' && throttle !=

null) {

clearTimeout(throttle);

}

throttle = setTimeout(update_dims, 100, “replace”);

“”"

dims = ColumnDataSource(dict(width=[ plot_width],
height=[plot_height] ))

          fig.x_range.callback = CustomJS(code=dims_jscode,

args=dict(plot=fig, dims=dims))

    On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de > > ven wrote:
      I would

only keep in mind: CustomJS callbacks will execute in the
browser, essentially immediately, while any python callback
will execute in a Bokeh server after a network protocol
exchange. So “same time” has to be interpreted with some
looseness. If you have two unrelated tasks, things should be
fine. If you need to enforce some ordering or synchronization
between the two types of callbacks, that’s probably not
possible (except that the CustomJS will “probably” always
execute first, but no guarantees there either).

      Thanks,




      Bryan





      > On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]          > > > > wrote:


      >

      > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


      >

      > On 8/4/16 1:33 AM, Bill wrote:


      >> Thank you for reading. I googled a lot but cannot

find an answer, so I might try my luck here.

      >>

      >> I am running a bokeh server. When a widget (say, a

button) is clicked, a python function is triggered. However, I
want to run some javascript code at the same time. Is it
possible? Thanks for any advice.

      >> --

      >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)          .


      >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)          .


      >

      > --

      > Sarah Bird


      > Developer, Bokeh

      >

      >  


      >

      >

      > --

      > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)          .


      > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" style="width:150px;min-height:30px" height="30px" width="150px">
    ](http://continuum.io)

Hi,

JS callbacks are added with "js_on_change", not "on_change" (which is only for real python callbacks)

Regarding posts here, I am not sure it matters, we are now encouraging people to use Stack Overflow as the primary place to go for support (so that there will be one main place to monitor, instead of three). ththy The mailing list can then be more for lengthy or involved discussions (SO is not great for those).

Bryan

···

On Oct 15, 2017, at 14:38, Dan Kovacek <[email protected]> wrote:

From the docs I understand that "CustomJS callbacks can be attached to property change events on any Bokeh model". Are Div and PreText considered models?

Since PreText has a 'text' attribute, Should be able to call pretext_object.on_change('text', callback)?

I tried the following to no avail:

results = PreText(text='test')

toggle_pulse = dict()

toggle_pulse = CustomJS(args=toggle_pulse, code='''
var this_id = cb_obj.attributes['id'];
var input_div = document.getElementById(this_id);
var target_div = $(input_div).parent().parent().siblings()[0];
target_div.style.display = 'none';
''')

#(another set of functions calculates results and updates the pretext results object)

results.on_change('text', toggle_pulse)

Also, what's protocol on responding to old posts? Is there a 'too old' where the latest Bokeh version is too old to make the original post relevant, or is it better for searching purposes to use related threads whenever possible?

Thanks!

Dan

On Friday, August 5, 2016 at 5:59:41 AM UTC-7, Sarah Bird wrote:
Bokeh in general needs events to fire actions. The server will accept "periodic callbacks" and from that you should be able to read the width and height.

If you're just putting some JS on your page to inspect your bokeh items you can use the `Bokeh.index` to find your plot and start inspecting it.

So I think you could build a function like that that uses Bokeh.index to get at your bokeh objects and then call it at will.

On 8/4/16 8:35 AM, Bill wrote:

Thank you both for the help. If I understand, I can use .on_change method to call python function, and .callback attribute to call CustomJS?

Actually I wanted to do something a little different. I am trying to get the width and height of a plot using the following JS. I found a solution online which is to attach this JS to x_range.callback. However, I am wondering if there is a way to call this JS directly without needing to change x range first.

Hope this make sense. Thank you.

dims_jscode = """
var update_dims = function () {
    var new_data = {};
    new_data['height'] = [plot.plot_canvas.frame.get('height')];
    new_data['width'] = [plot.plot_canvas.frame.get('width')];
    dims.set('data', new_data);
};
if (typeof throttle != 'undefined' && throttle != null) {
    clearTimeout(throttle);
}
throttle = setTimeout(update_dims, 100, "replace");
"""

dims = ColumnDataSource(dict(width=[plot_width], height=[plot_height] ))
fig.x_range.callback = CustomJS(code=dims_jscode, args=dict(plot=fig, dims=dims))

On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de ven wrote:
I would only keep in mind: CustomJS callbacks will execute in the browser, essentially immediately, while any python callback will execute in a Bokeh server after a network protocol exchange. So "same time" has to be interpreted with some looseness. If you have two unrelated tasks, things should be fine. If you need to enforce some ordering or synchronization between the two types of callbacks, that's probably not possible (except that the CustomJS will "probably" always execute first, but no guarantees there either).

Thanks,

Bryan

> On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]> wrote:
>
> Try adding a seperate CustomJS callback: bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html
>
> On 8/4/16 1:33 AM, Bill wrote:
>> Thank you for reading. I googled a lot but cannot find an answer, so I might try my luck here.
>>
>> I am running a bokeh server. When a widget (say, a button) is clicked, a python function is triggered. However, I want to run some javascript code at the same time. Is it possible? Thanks for any advice.
>> --
>> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io\.
>> For more options, visit https://groups.google.com/a/continuum.io/d/optout\.
>
> --
> Sarah Bird
> Developer, Bokeh
>
>
>
>
> --
> 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io\.
> 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 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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

--
Sarah Bird
Developer, Bokeh

--
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/0929c4ae-b53b-4ec6-bed3-479770092a6d%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

I was able to successfully apply your strategy

Here is what I did in dummy code

button.on_click(button_callback)

pretext = PreText(text=“”)

pretext_callback = CustomJS(args=dict(source=export_csv_source),code=open(os.path.join(os.path.dirname(file), “JavaScript/download.js”)).read())

pretext.js_on_change(“text”
, pretext_callback)
def button_callback():

global export_csv_source

     for file in file_array:

read data

process data

export_csv_source.data = processed data

pretext.text = file.filename # it is this that triggers the CustomJS, whilst at the same time it shows the user which file is being exported

···

On Sunday, 15 October 2017 21:38:15 UTC+2, Dan Kovacek wrote:

From the docs I understand that “CustomJS callbacks can be attached to property change events on any Bokeh model”. Are Div and PreText considered models?

Since PreText has a ‘text’ attribute, Should be able to call pretext_object.on_change(‘text’, callback)?

I tried the following to no avail:

results = PreText(text=‘test’)

toggle_pulse = dict()

toggle_pulse = CustomJS(args=toggle_pulse, code=‘’’
var this_id = cb_obj.attributes[‘id’];
var input_div = document.getElementById(this_id);
var target_div = $(input_div).parent().parent().siblings()[0];
target_div.style.display = ‘none’;
‘’')

#(another set of functions calculates results and updates the pretext results object)

results.on_change(‘text’, toggle_pulse)

``

``

Also, what’s protocol on responding to old posts? Is there a ‘too old’ where the latest Bokeh version is too old to make the original post relevant, or is it better for searching purposes to use related threads whenever possible?

Thanks!

Dan

On Friday, August 5, 2016 at 5:59:41 AM UTC-7, Sarah Bird wrote:

Bokeh in general needs events to fire actions. The server will
accept “periodic call backs” and
from that you should be able to read the wi dth and
height.

If you’re just putting some JS on your page to
inspect you r
bokeh items you can use the
Bokeh.index to find your plot and start
inspecting it.

                                So I think you

cou ld
build a function like that that
uses Bokeh.index to get at your bokeh object s
and then c all
it at will.

On 8/4/16 8:35 AM, Bill wrote:

      Thank you both for the help. If I

understand, I can use .on_change method to call python
function, and .callback attribute to call CustomJS?

      Actually I wanted

to do something a little different. I am trying to get the
width and height of a plot using the following JS. I found a
solution online which is to attach this JS to
x_range.callback. However, I am wondering if there is a way to
call this JS directly without needing to change x range first.

      Hope this make

sense. Thank you.

dims_jscode = “”"

var update_dims = function () {

var new_data = {};

        new_data['height'] =

[plot.plot_canvas.frame.get(‘height’)];

        new_data['width'] =

[plot.plot_canvas.frame.get(‘width’)];

dims.set(‘data’, new_data);

};

        if (typeof throttle != 'undefined' && throttle !=

null) {

clearTimeout(throttle);

}

throttle = setTimeout(update_dims, 100, “replace”);

“”"

dims = ColumnDataSource(dict(width=[ plot_width],
height=[plot_height] ))

          fig.x_range.callback = CustomJS(code=dims_jscode,

args=dict(plot=fig, dims=dims))

    On Thursday, August 4, 2016 at 9:35:48 PM UTC+8, Bryan Van de > > > ven wrote:
      I would

only keep in mind: CustomJS callbacks will execute in the
browser, essentially immediately, while any python callback
will execute in a Bokeh server after a network protocol
exchange. So “same time” has to be interpreted with some
looseness. If you have two unrelated tasks, things should be
fine. If you need to enforce some ordering or synchronization
between the two types of callbacks, that’s probably not
possible (except that the CustomJS will “probably” always
execute first, but no guarantees there either).

      Thanks,




      Bryan





      > On Aug 4, 2016, at 8:05 AM, Sarah Bird - Continuum <[email protected]          > > > > > wrote:


      >

      > Try adding a seperate CustomJS callback: [bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html](http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html)


      >

      > On 8/4/16 1:33 AM, Bill wrote:


      >> Thank you for reading. I googled a lot but cannot

find an answer, so I might try my luck here.

      >>

      >> I am running a bokeh server. When a widget (say, a

button) is clicked, a python function is triggered. However, I
want to run some javascript code at the same time. Is it
possible? Thanks for any advice.

      >> --

      >> 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/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/4c11b432-af5a-4d39-80b0-2ddc2b6e97fc%40continuum.io)          .


      >> For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout)          .


      >

      > --

      > Sarah Bird


      > Developer, Bokeh

      >

      >  


      >

      >

      > --

      > 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/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/e4e816d4-560f-507f-73f7-0415430e1661%40continuum.io)          .


      > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](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/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/81999c26-c871-463c-b1e3-49494ea325bb%40continuum.io?utm_medium=email&utm_source=footer).

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


Sarah Bird
Developer, Bokeh

    [
      <img alt="Continuum Analytics" src="https://lh6.googleusercontent.com/proxy/VYgVjggTk1hCXSN9wFkffE3I6kxTvJ51tT4KvDXOuKbs1WyFG66k7kt2-vkDimbyxfWtP-d1paJmstMYhPPnDYSUF4rLPoYM2GM2QFM=w5000-h5000" style="width:150px;min-height:30px" height="30px" width="150px">
    ](http://continuum.io)

Ko saya tidak bisa mendawnload atau ada masalah tolong dong di perbaiki