-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Update cycle broken after callback #159
Comments
I think I see what's going on here:
Another thing to note - which I imagine you all are well aware of but it's a significant limitation of this component today - is that @app.callback(
Output("html-cytoscape", "children"),
Input("button-cytoscape", "n_clicks"),
Input("cytoscape", "elements"),
)
def testCytoscape(n_clicks, elements):
if n_clicks:
return json.dumps(elements) Ideally you'd be able to click the JSON button (to get the json to display at all) and then every time a node is moved you would see the new positions. But that doesn't happen: to get the updated positions to show up you have to click the JSON button again. The ideal solution here is to watch events that cause changes in |
Great. Here are some suggestions to help expedite things:
(1) The most important events to listen to are, in descending order, ‘add’, ‘remove’, ‘data’, ‘position’, ’select’, ‘unselect’, and ‘viewport’. The full list is here, but not all of them would affect this the data: https://js.cytoscape.org/#events <https://js.cytoscape.org/#events> Some states, like selection, are handled with special cases in Dash Cytoscape already, though I agree that a general solution would be preferable.
(2) For performance reasons, it may be useful to throttle — or ideally, debounce — the callback(s), especially if the entire graph JSON is sent for each update. This may depend on the use cases you envision the component supporting. E.g., debouncing doesn’t fit as well if the consumer wants intermediary dragging positions.
… On Oct 25, 2021, at 14:51, Alex Johnson ***@***.***> wrote:
I think I see what's going on here:
When we initially render the component, the elements array is used directly in the cytoscape instance.
That means that changes made in-place to that array internally by Cytoscape are reflected in the renderer's layout object.
But when we update elements, a new object is inserted into the renderer's layout but internally to the component the original object is patched <https://github.com/plotly/react-cytoscapejs/blob/eadd9598a07978c66e9a0eb997cd8340cf76aa0a/src/component.js#L84> to match the new object, rather than simply replaced by the new object.
So after an update - any update where a new elements array was created by a callback - the one inside the Cytoscape instance is no longer the same one as in layout so updates will not be reflected there.
Another thing to note - which I imagine you all are well aware of but it's a significant limitation of this component today - is that elements does not function as an Input. So if I take the first callback above and change it to:
@app.callback(
Output("html-cytoscape", "children"),
Input("button-cytoscape", "n_clicks"),
Input("cytoscape", "elements"),
)
def testCytoscape(n_clicks, elements):
if n_clicks:
return json.dumps(elements)
Ideally you'd be able to click the JSON button (to get the json to display at all) and then every time a node is moved you would see the new positions. But that doesn't happen: to get the updated positions to show up you have to click the JSON button again.
The ideal solution here is to watch events that cause changes in elements, and have the component call setProps({elements: newElements}) - that would propagate the changes back into layout, fixing the case raised in this PR and allowing elements to be used as an Input.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub <#159 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAHRO42ITYN7P7Q5O4HPW4TUIWRLDANCNFSM5GVXIT7Q>.
|
Hi all, I've been looking to better understand my issue (#167), and I'm now thinking mine is a duplicate of this. Could you let me know if
My use-case really depends on being able to submit a new |
Description
After running a callback with
Output
andState
on the graph JSON, the update cycle is broken.This affects Scale AI and Hydro Quebec.
CC: @mtwichan @alexcjohnson @mj3cheun @jackparmer
Steps/Code to Reproduce
This is a minimal example adapted from another reproducible example from Matthew (@mtwichan). You can drag around the nodes in the demo to easily demonstrate the issue:
Notes:
data
), though position is simple and clear to demonstrate.usage.py
to quickly verify.Expected Results
The update cycle should continue.
Actual Results
The update cycle is stopped.
Versions
@mtwichan, would you post your versions here for reference?
The text was updated successfully, but these errors were encountered: