callback if condition can not work

is_sub_plot_display = False

def hide_display_plot(source=source, ts1=ts1, ts2 = ts2):

global is_sub_plot_display

if is_sub_plot_display == False:

ts2.background_fill_color = ts1.background_fill_color

is_sub_plot_display = True

elif is_sub_plot_display == True:

ts2.background_fill_color = “white”

is_sub_plot_display = False

else:

ts2.background_fill_color = “yellow”

taptool.callback = CustomJS.from_py_func(hide_display_plot)

``

Can anyone show their talent and let me know why if condition does not work when I call tap callback. thanks a lot

So far, I can tell “global” does not work.

···

On Friday, June 8, 2018 at 1:48:22 PM UTC-6, peng wang wrote:

is_sub_plot_display = False

def hide_display_plot(source=source, ts1=ts1, ts2 = ts2):

global is_sub_plot_display

if is_sub_plot_display == False:

ts2.background_fill_color = ts1.background_fill_color

is_sub_plot_display = True

elif is_sub_plot_display == True:

ts2.background_fill_color = “white”

is_sub_plot_display = False

else:

ts2.background_fill_color = “yellow”

taptool.callback = CustomJS.from_py_func(hide_display_plot)

``

Can anyone show their talent and let me know why if condition does not work when I call tap callback. thanks a lot

Hi,

There's definitely some misunderstanding to correct. CustomJS.from_py_func is a convenience that "translates" a python function into JavaScript, that gets run in the browser. But the code in the function can't do anything that JavaScript in the browser can't do. In particular, global can't function at all, because only things completely in the function get translated and make it to JavaScript. The code in the browser knows nothing at all about "is_sub_plot_display".

It's not quite clear what you are trying to accomplish at a high level, so I can't really offer more specific guidance.

Thanks,

Bryan

···

On Jun 8, 2018, at 13:14, peng wang <[email protected]> wrote:

So far, I can tell "global" does not work.

On Friday, June 8, 2018 at 1:48:22 PM UTC-6, peng wang wrote:
is_sub_plot_display = False
    def hide_display_plot(source=source, ts1=ts1, ts2 = ts2):
        global is_sub_plot_display
        if is_sub_plot_display == False:
            ts2.background_fill_color = ts1.background_fill_color
            is_sub_plot_display = True
        elif is_sub_plot_display == True:
            ts2.background_fill_color = "white"
            is_sub_plot_display = False
        else:
            ts2.background_fill_color = "yellow"

taptool.callback = CustomJS.from_py_func(hide_display_plot)

Can anyone show their talent and let me know why if condition does not work when I call tap callback. thanks a lot

--
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/0042db5a-8ded-4e39-a76c-31d3f12d1df8%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

thanks a lot for those valuable feedback. If I do need a global variable to implement my logic, what suggestion? cheers.

···

On Friday, June 8, 2018 at 3:34:07 PM UTC-6, Bryan Van de ven wrote:

Hi,

There’s definitely some misunderstanding to correct. CustomJS.from_py_func is a convenience that “translates” a python function into JavaScript, that gets run in the browser. But the code in the function can’t do anything that JavaScript in the browser can’t do. In particular, global can’t function at all, because only things completely in the function get translated and make it to JavaScript. The code in the browser knows nothing at all about “is_sub_plot_display”.

It’s not quite clear what you are trying to accomplish at a high level, so I can’t really offer more specific guidance.

Thanks,

Bryan

On Jun 8, 2018, at 13:14, peng wang [email protected] wrote:

So far, I can tell “global” does not work.

On Friday, June 8, 2018 at 1:48:22 PM UTC-6, peng wang wrote:

is_sub_plot_display = False

def hide_display_plot(source=source, ts1=ts1, ts2 = ts2):
    global is_sub_plot_display
    if is_sub_plot_display == False:
        ts2.background_fill_color = ts1.background_fill_color
        is_sub_plot_display = True
    elif is_sub_plot_display == True:
        ts2.background_fill_color = "white"
        is_sub_plot_display = False
    else:
        ts2.background_fill_color = "yellow"

taptool.callback = CustomJS.from_py_func(hide_display_plot)

Can anyone show their talent and let me know why if condition does not work when I call tap callback. thanks a lot


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/0042db5a-8ded-4e39-a76c-31d3f12d1df8%40continuum.io.

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

by the way, I use Bokeh server, flask.

···

On Friday, June 8, 2018 at 3:34:07 PM UTC-6, Bryan Van de ven wrote:

Hi,

There’s definitely some misunderstanding to correct. CustomJS.from_py_func is a convenience that “translates” a python function into JavaScript, that gets run in the browser. But the code in the function can’t do anything that JavaScript in the browser can’t do. In particular, global can’t function at all, because only things completely in the function get translated and make it to JavaScript. The code in the browser knows nothing at all about “is_sub_plot_display”.

It’s not quite clear what you are trying to accomplish at a high level, so I can’t really offer more specific guidance.

Thanks,

Bryan

On Jun 8, 2018, at 13:14, peng wang [email protected] wrote:

So far, I can tell “global” does not work.

On Friday, June 8, 2018 at 1:48:22 PM UTC-6, peng wang wrote:

is_sub_plot_display = False

def hide_display_plot(source=source, ts1=ts1, ts2 = ts2):
    global is_sub_plot_display
    if is_sub_plot_display == False:
        ts2.background_fill_color = ts1.background_fill_color
        is_sub_plot_display = True
    elif is_sub_plot_display == True:
        ts2.background_fill_color = "white"
        is_sub_plot_display = False
    else:
        ts2.background_fill_color = "yellow"

taptool.callback = CustomJS.from_py_func(hide_display_plot)

Can anyone show their talent and let me know why if condition does not work when I call tap callback. thanks a lot


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/0042db5a-8ded-4e39-a76c-31d3f12d1df8%40continuum.io.

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