Hello,
I am trying to update figure on selection but it doesn’t turn back when when clicked “reset” or double-click
app = Dash(
suppress_callback_exceptions=True
)
def getGraph(x,y,selectedData):
selectedPoints,unselectedPoints = getPoints(x,y,selectedData)
fig = go.Figure()
fig.add_trace(
go.Scatter(
x = selectedPoints[:,0],
y = selectedPoints[:,1],
mode="markers",
marker=dict(color="crimson"),
name="selectedScatter"
)
)
fig.add_trace(
go.Scatter(
x = unselectedPoints[:,0],
y = unselectedPoints[:,1],
mode="markers",
name="unselectedScatter",
marker=dict(color="cyan")
)
)
return fig
num_size = 1000
x = np.random.random_integers(low=0,high=100,size=num_size)
y = np.random.random_integers(low=0,high=100,size=num_size)
originalFig = go.Figure()
originalFig.add_trace(
go.Scatter(
x=x,
y=y,
mode="markers",
marker=dict(color="cyan")
)
)
app.layout = html.Div(
[
html.Div(
dcc.Graph(
id="the-graph",
style={
"width":"90vw"
}
),
style= {
"display":"flex",
"align-items":"center",
"justify-content":"center"
}
),
]
)
@callback(
Output("the-graph","figure"),
Input("the-graph","selectedData")
)
def updateFigure(selectedData):
if selectedData:
return getGraph(x,y,selectedData)
else:
return originalFig
app.run_server()
I observed that when selected using “box-select” or “lassoSelect” then selectedData dict is generated populating it from null to dict but after the figure is updated the selectedData turns back to empty list and not null, it becomes
selectedData = {“points”:}
I would like it to revert back to originalFig when double-click event, but I haven’t found anything related to that.
is there a way to rectify this?