-
Notifications
You must be signed in to change notification settings - Fork 7
chore: Plumb query results to graph server/colab callback via python globals, rather than html/javascript #205
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -633,8 +633,9 @@ def _handle_result(result, args): | |
|
|
||
|
|
||
| def _colab_query_callback(query: str, params: str): | ||
| query_results = json.loads(graph_server.graph_server.query_result.to_json()) | ||
| return IPython.core.display.JSON( | ||
| graph_server.convert_graph_data(query_results=json.loads(params)) | ||
| graph_server.convert_graph_data(query_results=query_results) | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -697,11 +698,13 @@ def _add_graph_widget(query_result): | |
| singleton_server_thread = graph_server.graph_server.init() | ||
| port = graph_server.graph_server.port | ||
|
|
||
| graph_server.graph_server.query_result = query_result | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a single global variable A more robust solution would be to avoid this shared state. For example, you could store query results in a dictionary keyed by a unique ID:
This would make the visualization mechanism stateless and safe for concurrent executions.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a bad suggestion, but I have not encountered a notebook environment that allows more than one cell to run at a time, so it's not a huge concern for me. |
||
|
|
||
| # Create html to invoke the graph server | ||
| html_content = generate_visualization_html( | ||
| query="placeholder query", | ||
| port=port, | ||
| params=query_result.to_json().replace("\\", "\\\\").replace('"', '\\"'), | ||
| params="{}", | ||
| ) | ||
| IPython.display.display(IPython.core.display.HTML(html_content)) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
queryandparamsarguments are no longer used in this function. It's a good practice to prefix unused variables with an underscore to make the code clearer.