Show/hide line glyph with bokeh server

Hi all

Would it be possible to hide/show this line plot by pressing the button named “first”?

My initial idea was to create a CollumnDataFrame with a 0 and 1, and then use these values as the input for the line alpha.

But is this possible and how would it be done? Is it possible for a single line glyph to have two different Source?

I know this is a “hackish” way of doing it, but I haven’t found any alternative ways?

The code below is a modification of the “simple_hdf5” example I’ve made. But right now I cannot seem to get past the fact of having two sources for p.line(…

data_select = Select(title=“Output:”, value=“hip_strength”, options=[“hip_strength”, “knee_strength”])
checkbox_button_group = CheckboxButtonGroup(labels=[“first”, “second”], active=[0, 1])

source = ColumnDataSource(data=dict(x=, y=))
checkbox_source = ColumnDataSource(data=dict(first=, second=))

p = Figure(plot_height=600, plot_width=800, title=“”, toolbar_location=None)
p.line(x=“x”, y=“y”, alpha=“first”, source=source)

This is the result right now. Nothing happens when I press first, but I would like the line to disappear.

The entire code is here: https://github.com/KasperPRasmussen/bokeh/tree/master/examples/app/ShowAndHideLine


Best regards, Kasper

Hi Kasper,

You should just be able to set the glyph's alpha values directly. First, store the renderer for the glyph:

  renderer = p.line(...)

Then in a callback you could do:

  renderer.glyph.line_alpha = 0

or

  renderer.glyph.line_color = None

There is more information here in the user's guide:

  Appearance — Bokeh 3.3.2 Documentation

Thanks,

Bryan

···

On Apr 18, 2016, at 7:06 AM, Kasper Pihl Rasmussen <[email protected]> wrote:

Hi all

Would it be possible to hide/show this line plot by pressing the button named "first"?

My initial idea was to create a CollumnDataFrame with a 0 and 1, and then use these values as the input for the line alpha.
But is this possible and how would it be done? Is it possible for a single line glyph to have two different Source?

I know this is a "hackish" way of doing it, but I haven't found any alternative ways?

The code below is a modification of the "simple_hdf5" example I've made. But right now I cannot seem to get past the fact of having two sources for p.line(...
data_select = Select(title="Output:", value="hip_strength", options=["hip_strength", "knee_strength"])
checkbox_button_group = CheckboxButtonGroup(labels=["first", "second"], active=[0, 1])

source = ColumnDataSource(data=dict(x=, y=))
checkbox_source = ColumnDataSource(data=dict(first=, second=))

p = Figure(plot_height=600, plot_width=800, title="", toolbar_location=None)
p.line(x="x", y="y", alpha="first", source=source)

This is the result right now. Nothing happens when I press first, but I would like the line to disappear.
The entire code is here: https://github.com/KasperPRasmussen/bokeh/tree/master/examples/app/ShowAndHideLine

Best regards, Kasper

--
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/65472f8d-be97-47b0-be41-709aa2abb8ea%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks Bryan

What you wrote are working perfectly. I used some time to figure out how whether the “.on_click” needed to run through my "update_data(attrname, old, new) which it didn’t.

I got my epiphany of how to put it together when I found the “buttons_server.py” example (For others trying the same).

For anyone interested, there is a smal example here: show/hide example

Best regards,

Kasper

Thanks for sharing, i’ll try and incorporate this into an example next time I’m working on one. Seems like something lots of people would want to know how to do.

Sarah Bird
[email protected]

···

On Apr 19, 2016, at 6:46 AM, Kasper Pihl Rasmussen [email protected] wrote:

Thanks Bryan

What you wrote are working perfectly. I used some time to figure out how whether the “.on_click” needed to run through my "update_data(attrname, old, new) which it didn’t.

I got my epiphany of how to put it together when I found the “buttons_server.py” example (For others trying the same).

For anyone interested, there is a smal example here: show/hide example

Best regards,

Kasper

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/e922fadc-f24c-4dc2-907a-6f15b4654423%40continuum.io.

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