@@ -640,23 +640,30 @@ def _add_graph_widget(query_result):
640
640
# visualizer widget. In colab, we are not able to create an http server on a
641
641
# background thread, so we use a special colab-specific api to register a callback,
642
642
# to be invoked from Javascript.
643
+ port = None
643
644
try :
644
645
from google .colab import output
645
646
646
647
output .register_callback ("graph_visualization.Query" , _colab_query_callback )
647
648
output .register_callback (
648
649
"graph_visualization.NodeExpansion" , _colab_node_expansion_callback
649
650
)
651
+
652
+ # In colab mode, the Javascript doesn't use the port value we pass in, as there is no
653
+ # graph server, but it still has to be set to avoid triggering an exception.
654
+ # TODO: Clean this up when the Javascript is fixed on the spanner-graph-notebook side.
655
+ port = 0
650
656
except ImportError :
651
657
global singleton_server_thread
652
658
alive = singleton_server_thread and singleton_server_thread .is_alive ()
653
659
if not alive :
654
660
singleton_server_thread = graph_server .graph_server .init ()
661
+ port = graph_server .graph_server .port
655
662
656
663
# Create html to invoke the graph server
657
664
html_content = generate_visualization_html (
658
665
query = "placeholder query" ,
659
- port = graph_server . graph_server . port ,
666
+ port = port ,
660
667
params = query_result .to_json ().replace ("\\ " , "\\ \\ " ).replace ('"' , '\\ "' ),
661
668
)
662
669
IPython .display .display (IPython .core .display .HTML (html_content ))
0 commit comments