-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken click_data event on plotly data point since panel 1.x.x #5096
Comments
I'm trying to help a user on Discord in https://discourse.holoviz.org/t/updating-a-selectbox-dependent-plotly-scatterplot-based-on-click-events/5542. I'm on Panel 1.1.0 and Plotly plotly-5.15.0. I'm also hit by this. In the below example I would expect the import panel as pn
import param
import plotly.express as px
import pandas as pd
# 1. Configure your application
# Remember to list your "dependencies" like plotly here!
pn.extension("plotly", sizing_mode="stretch_width")
# 2. Optionally create a Parameterized class to hold (some of) your application state
class AppState(param.Parameterized):
click_data = param.Parameter()
state = AppState()
# 2. Extract your data. Add caching if needed
@pn.cache
def get_data():
return pd.DataFrame({
'Stat1': [5, 8, 3, 6],
'Stat2': [7, 10, 4, 8],
'Stat3': [9, 12, 6, 10],
'Stat4': [4, 6, 2, 5]
})
data = get_data()
# 3. Transform your data. Add caching if needed
@pn.cache
def get_plot(graph_option1, graph_option2, click_data=None, data=data):
fig = px.bar(data, x=graph_option1, y=graph_option2, title=f'{graph_option1}, {graph_option2}, {click_data}')
fig.layout.autosize=True
return fig
# 4. Define your widgets and optionally some panes and layouts
graph_options = list(data)
graph_option1 = pn.widgets.Select(name="x-axis Stat:",
options=graph_options, value="Stat1")
graph_option2 = pn.widgets.Select(name="y-axis Stat:",
options=graph_options, value="Stat2")
# 5. Bind your functions to widgets
# Panel will then know it needs to rerun the function when the value of a widget changes
bound_plot = pn.bind(get_plot, graph_option1=graph_option1, graph_option2=graph_option2, click_data=state.param.click_data)
# Optionally provide your bound functions to Panes or other widgets
# In Panel 1.x you can provide *bound* functions as arguments to Panel panes, widgets and layouts
plot_pane = pn.pane.Plotly(bound_plot)
def update(click_data):
state.param.update(click_data=click_data)
print("update", click_data)
pn.bind(update, click_data=plot_pane.param.click_data, watch=True)
# 6. Layout your components
# 7. Wrap it up in a nice template
pn.template.FastListTemplate(
title="Reacting to Plotly events",
sidebar=[graph_option1, graph_option2],
main=[plot_pane]
).servable() UpdateIf I click the 2nd bar from the left first a |
The |
I tried downgrading to Panel 0.14.4. But keeping Plotly 5.15. The import panel as pn
import param
import plotly.express as px
import pandas as pd
import mimetypes
mimetypes.add_type("application/javascript", ".js")
# 1. Configure your application
# Remember to list your "dependencies" like plotly here!
pn.extension("plotly", sizing_mode="stretch_width")
# 2. Optionally create a Parameterized class to hold (some of) your application state
class AppState(param.Parameterized):
click_data = param.Parameter()
state = AppState()
# 2. Extract your data. Add caching if needed
@pn.cache
def get_data():
return pd.DataFrame({
'Stat1': [5, 8, 3, 6],
'Stat2': [7, 10, 4, 8],
'Stat3': [9, 12, 6, 10],
'Stat4': [4, 6, 2, 5]
})
data = get_data()
# 3. Transform your data. Add caching if needed
@pn.cache
def get_plot(graph_option1, graph_option2, click_data=None, data=data):
fig = px.bar(data, x=graph_option1, y=graph_option2, title=f'{graph_option1}, {graph_option2}, {click_data}')
fig.layout.autosize=True
return fig
# 4. Define your widgets and optionally some panes and layouts
graph_options = list(data)
graph_option1 = pn.widgets.Select(name="x-axis Stat:",
options=graph_options, value="Stat1")
graph_option2 = pn.widgets.Select(name="y-axis Stat:",
options=graph_options, value="Stat2")
plot_pane = pn.pane.Plotly()
# 5. Bind your functions to widgets
# Panel will then know it needs to rerun the function when the value of a widget changes
def get_plot_helper(graph_option1=graph_option1, graph_option2=graph_option2, click_data=state.param.click_data, data=data):
print("update")
plot_pane.object=get_plot(graph_option1=graph_option1, graph_option2=graph_option2, click_data=click_data, data=data)
bound_plot = pn.bind(get_plot_helper, graph_option1=graph_option1, graph_option2=graph_option2, click_data=state.param.click_data, watch=True)
bound_plot()
# 6. Layout your components
# 7. Wrap it up in a nice template
pn.template.FastListTemplate(
title="Reacting to Plotly events",
sidebar=[graph_option1, graph_option2],
main=[plot_pane]
).servable() |
I noticed that the panel: 1.3.1
The example on https://panel.holoviz.org/reference/panes/Plotly.html also only works if you click on the 'Box Select' button on the plot. |
This is still a problem with Panel==1.4.1. I would have like to add an example of import pandas as pd
import panel as pn
import plotly.express as px
pn.extension("plotly")
data = pd.DataFrame([
('Monday', 7), ('Tuesday', 4), ('Wednesday', 9), ('Thursday', 4),
('Friday', 4), ('Saturday', 4), ('Sunday', 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.layout.autosize = True
responsive = pn.pane.Plotly(fig, height=300)
pn.Row(responsive.controls(), responsive).servable() Notice that the click_data_not_working.mp4UPDATE: As soon as you select the Box or Lasso selection tool, |
ALL software version info
Chrome 113
Python 3.11.4
Description of expected behavior and the observed behavior
Observed behavior
Clicking on one of the data points either doesn't trigger the Python
click_data
callback handler or it triggers the callback handler with wrong customdata (e.g. url).For example, I clicked on every data point, but the Python callback was only fired for the first one:
I'm experiencing this issue since panel 1.x.x
Expected behavior
Clicking on a data point fires the Python
click_data
event handler on every click with the associated customdata.Complete, minimal, self-contained example code that reproduces the issue
Run the code with
panel serve dashboard.py
. While clicking on one of the data points, the job name, duration and job url should be printed on the consoleStack traceback and/or browser JavaScript console output
No error message in the Browser's console log or in the server's output
The text was updated successfully, but these errors were encountered: