Getting focus back to the select

Hi,

Hope you are all safe and well.

When I update a panel containing an Holoview plot from a Select widget the focus disappears from the selector. I assume it goes to the Holoviews panel.

Is there a way I can maintain the focus on the selector? I’d like to step through the values of the selector using the arrow keys. This is the usual way the selector works.

Callback snippet that loses focus…

def set_hv_layout_event(hv_layout, event):
    set_hv_layout(_id=event.new)
    # How to get the focus back to `select` here?

select.link(hv_layout, callbacks={'value': set_hv_layout_event})    

Thanks,

Douglas

Hi @douglasmacdonald

Could you provide a minimal, reproducible example? That would make your problem very specific and reproducible. Thanks.

Hi,

Example

pn.__version__

‘0.10.2’

This keeps focus on the select…

select = pn.widgets.Select(name='file', options=[1, 2, 3])
hv_layout = pn.panel(hv.Curve([]))

def callback(event):
    pass
    

select.param.watch(callback, ['value'], onlychanged=True)
pn.Column(select, hv_layout)

This loses focus on the select…

select = pn.widgets.Select(name='file', options=[1, 2, 3])
hv_layout = pn.panel(hv.Curve([]))

def callback(event):
    hv_layout.object = hv.Curve([])
    

select.param.watch(callback, ['value'], onlychanged=True)
pn.Column(select, hv_layout)

(Note focus is maintained if I used functions and interact, however, I need to dynamically populate the options for select and was not sure how to do this with interact.)

Thanks,

Douglas

1 Like

Would recommend using a DynamicMap here which ensures it doesn’t rerender the plot (which I assume is responsible for the loss of focus.

select = pn.widgets.Select(name='file', options=[1, 2, 3])

def callback(value):
    return hv.Curve([])

pn.Column(select, hv.DynamicMap(pn.bind(callback, value=select)))

Will this work for your usecase?

2 Likes

Yes, this works.Thank you.

Should I have known this from the docs?

Best,
Douglas

Hi,

It worked but not with DynamicMap but using bind instead of watch. Note, in my case, I was displaying HexPlots.

Best,
Douglas