# Bokeh legend callback issue

**URL:** <https://discourse.bokeh.org/t/bokeh-legend-callback-issue/12378>\
**Category:** Community Support\
**Tags:** customjs\
**Created:** [March 28, 2025, 8:04pm UTC](https://discourse.bokeh.org/t/bokeh-legend-callback-issue/12378 "2025-03-28T20:04:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulM](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@PaulM](https://discourse.bokeh.org/u/PaulM)\
**Post date:** [March 28, 2025, 8:04pm UTC](https://discourse.bokeh.org/t/bokeh-legend-callback-issue/12378/1 "2025-03-28T20:04:41Z")

</div>

I’m in the process of updating some code from Bokeh 1.4 to Bokeh 3.7. One part of the code uses CustomJS to control the position of a legend using a select widget. The options are things like “Top Left”, “Top Center”, etc., and after the user makes their selection, the legend automatically moves to the new location.

In Bokeh 3.7, the legend moves to the correct location, but it loses the line drawings. The line drawings come back if I click on the legend.

Here are some images to illustrate the issue.

 ![BokehIssue](https://discourse-uploads.bokeh.org/original/2X/2/2fbe538b94f78333ce3016552e4658dc555d8a3c.jpeg)

I’m using Python 3.13 and Bokeh 3.7. Here is the code snippet defining the callback when someone makes a dropdown selection

```auto
callback = CustomJS(
            args={
                'pos_select': pos_select,
                'legend': legend
            },
            code="""
                var pos = pos_select.value.toLowerCase().replace(' ', '_');
                if(pos === 'hide_legend'){
                    legend.visible = false;
                } else {
                    legend.location = pos;
                    legend.visible = true;
                }
                legend.change.emit();

                // Need to reapply the bokeh styles after making changes.
                applyBokehStyles();
            """
        )
pos_select.js_on_change('value', callback)

```

I have no idea what needs to be changed for this to work in Bokeh 3.7. Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [March 29, 2025, 2:20pm UTC](https://discourse.bokeh.org/t/bokeh-legend-callback-issue/12378/2 "2025-03-29T14:20:46Z")

</div>

It’s possible there’s a bug/regression or maybe there’s just some usage change. I’m happy to take a quick closer look but I’d need a [_ **complete** _ Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) that I can just drop in an editor and run directly without changes to investigate.

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [June 27, 2025, 2:21pm UTC](https://discourse.bokeh.org/t/bokeh-legend-callback-issue/12378/3 "2025-06-27T14:21:01Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
