Ok so here is my working.
First capture double click at user side(See dash py code below), after that capture click event on plotly sunburst plot (see javascript code below) - in this event, evaluate if user doubled clicked or single clicked, if it is double clicked - return false (the plotly graph doesn’t update i.e. the segments doesn’t zoom in / animate) otherwise true (the segments zoom in / do their animation)
Below is the code to capture double clicks - i wrote client side callback to capture double clicks. This piece of code just toggles a dummy graph based on double or single click.
import dash
from dash import dcc
from dash import html
from dash import ClientsideFunction
from dash.dependencies import Input, Output, State
import plotly.graph_objects as go
app = dash.Dash(__name__)
def dummy_graph():
fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name=f'Trace 1'))
fig.add_trace(go.Scatter(x=[4, 5, 6], y=[1, 2, 3], name=f'Trace 2'))
fig.add_trace(go.Scatter(x=[7, 8, 9], y=[1, 2, 3], name=f'Trace 3'))
fig.add_trace(go.Scatter(x=[10, 11, 12], y=[1, 2, 3], name=f'Trace 4'))
fig.add_trace(go.Scatter(x=[13, 14, 15], y=[1, 2, 3], name=f'Trace 5'))
fig.add_trace(go.Scatter(x=[13, 14, 15], y=[1, 2, 3], name=f'Trace 6'))
fig.add_trace(go.Scatter(x=[16, 17, 18], y=[1, 2, 3], name=f'Trace 7'))
fig.add_trace(go.Scatter(x=[19, 20, 21], y=[1, 2, 3], name=f'Trace 8'))
fig.add_trace(go.Scatter(x=[22, 23, 24], y=[1, 2, 3], name=f'Trace 9'))
fig.add_trace(go.Scatter(x=[25, 26, 27], y=[1, 2, 3], name=f'Trace 10'))
fig.update_layout(showlegend=True,
legend=dict(itemclick = False))
return fig
app.layout = html.Div([
html.Button('Click Me', id='output-double-click'), # Add a button to the layout
html.Div(id='output-message'),
dcc.Graph(id='graph'),
dcc.Store(id='last_click',data=False),
dcc.Store(id='dc_trig'),
])
app.clientside_callback(
"""
function(n_clicks, data)
{
let CLICK_TIME = (new Date()).getTime();
if(CLICK_TIME - data < 500)
{
console.log('double click');
return [(new Date()).getTime(), new Boolean(true)];
}
else
{
LAST_CLICK = CLICK_TIME
console.log('single click');
return [LAST_CLICK, new Boolean(false)];
}
console.log(data);
return [(new Date()).getTime(), new Boolean(false)];
}
""",
[Output('last_click', 'data'),Output('dc_trig', 'data')],
[Input('output-double-click', 'n_clicks'),State('last_click', 'data')],
prevent_initial_call=True
)
@app.callback(
Output("graph", "figure"),
[Input('dc_trig', 'data')],
prevent_initial_call=True
)
def dc_trigger_plot(data):
if(data == True):
# print("Double Clicked!.")
fig = dummy_graph()
return fig
else:
return {}
if __name__ == '__main__':
app.run_server(debug=True, port=8050)
The part of capturing double clicks works well.
Onto the second part - capture click event on plotly sunburst figure , is something i’m struggling with.
I found some JS code (linked below), which is for plotly.js - where plotly sunbrust click event is captured, and based on what is returned (true or false) - it either zooms in or not. I can’t replicate the same behavior in dash python.
See plotly js code here : https://codepen.io/etpinard/pen/GRKNyNO
My question : how do I capture ‘plotly_sunburstclick’ in dash python?
@jinnyzor @adamschroeder