Bind selected_data param from plotly chart

I am trying to access plotly’s box select values with python through the panel.bind function, but for some reason, the selected_data param does not appear to be updating. Here is an example:

import pandas as pd
import plotly.express as px
import panel as pn
pn.extension('plotly')

data = pd.DataFrame([
    ('Monday', 7), ('Tuesday', 4), ('Wednesday', 9), ('Thursday', 4),
    ('Friday', 4), ('Saturday', 4), ('Sunay', 4)], columns=['Day', 'Orders']
)

fig = px.line(data, x="Day", y="Orders")
fig.update_traces(mode="lines+markers", marker=dict(size=10), line=dict(width=4))
fig.update_layout(dragmode='select')

def get_select_range(selected_data):
    return selected_data

responsive = pn.pane.Plotly(fig, config={'responsive': True})
bound_fn = pn.bind(get_select_range, responsive.param.selected_data)

pn.Column('# A responsive plot', 
          responsive, 
          bound_fn, 
          sizing_mode='stretch_width')

If you replace the bind function with click data, everything works fine.

bound_fn = pn.bind(get_select_range, responsive.param.click_data)

Any ideas on what might be going on here? Thank you!

1 Like

Hello @Variably9781 and welcome. I executed your example in a fresh environment on windows (plotly 5.14.1, panel 1.1, python=3.10.11) in Edge browser. Everything works as expected.
Could you try with the new panel version and/or tell what your environment is?

Any updates here? I’m also facing this issue. Plotly 5.17.0, Panel 1.2.3 and Python 3.10.12