☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

callback if condition can not work

Community Support
peng_wang
peng_wang

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

⌁   Link to post
peng_wang
peng_wang

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

⌁   Link to post
Bryan
Bryan

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 <pmjz.wang@gmail.com> 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 bokeh+unsubscribe@continuum.io.
To post to this group, send email to bokeh@continuum.io.
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\.

⌁   Link to post
peng_wang
peng_wang

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

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

⌁   Link to post
peng_wang
peng_wang

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

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

⌁   Link to post

End of archived discussion · Replies are disabled