diff --git a/deephaven_ipywidgets/_version.py b/deephaven_ipywidgets/_version.py index ae8ad0a..5ffebe2 100644 --- a/deephaven_ipywidgets/_version.py +++ b/deephaven_ipywidgets/_version.py @@ -4,5 +4,5 @@ # Copyright (c) Deephaven Data Labs LLC. # Distributed under the terms of the Modified BSD License. -version_info = (0, 2, 0) +version_info = (0, 2, 1) __version__ = ".".join(map(str, version_info)) diff --git a/deephaven_ipywidgets/deephaven.py b/deephaven_ipywidgets/deephaven.py index ffb5252..acd9949 100644 --- a/deephaven_ipywidgets/deephaven.py +++ b/deephaven_ipywidgets/deephaven.py @@ -15,19 +15,21 @@ from uuid import uuid4 from ._frontend import module_name, module_version + def _str_object_type(obj): - """Returns the object type as a string value""" - return f"{obj.__class__.__module__}.{obj.__class__.__name__}" + """Returns the object type as a string value""" + return f"{obj.__class__.__module__}.{obj.__class__.__name__}" + def _path_for_object(obj): - """Return the iframe path for the specified object. Inspects the class name to determine.""" - name = _str_object_type(obj) + """Return the iframe path for the specified object. Inspects the class name to determine.""" + name = _str_object_type(obj) - if name in ('deephaven.table.Table', 'pandas.core.frame.DataFrame'): - return 'table' - if name == 'deephaven.plot.figure.Figure': - return 'chart' - raise TypeError(f"Unknown object type: {name}") + if name in ('deephaven.table.Table', 'pandas.core.frame.DataFrame'): + return 'table' + if name == 'deephaven.plot.figure.Figure': + return 'chart' + raise TypeError(f"Unknown object type: {name}") class DeephavenWidget(DOMWidget): @@ -60,9 +62,17 @@ def __init__(self, deephaven_object, height=600, width=0): # Generate a new table ID using a UUID prepended with a `t_` prefix object_id = f"t_{str(uuid4()).replace('-', '_')}" + port = Server.instance.port + server_url = f"http://localhost:{Server.instance.port}/" + + try: + from google.colab.output import eval_js + server_url = eval_js(f"google.colab.kernel.proxyPort({port})") + except ImportError: + pass + # Generate the iframe_url from the object type - server_url = f"http://localhost:{Server.instance.port}" - iframe_url = f"{server_url}/iframe/{_path_for_object(deephaven_object)}/?name={object_id}" + iframe_url = f"{server_url}iframe/{_path_for_object(deephaven_object)}/?name={object_id}" # Add the table to the main modules globals list so it can be retrieved by the iframe __main__.__dict__[object_id] = deephaven_object @@ -72,4 +82,4 @@ def __init__(self, deephaven_object, height=600, width=0): self.set_trait('object_id', object_id) self.set_trait('object_type', _str_object_type(deephaven_object)) self.set_trait('width', width) - self.set_trait('height', height) \ No newline at end of file + self.set_trait('height', height) diff --git a/deephaven_ipywidgets/tests/test_table.py b/deephaven_ipywidgets/tests/test_table.py index dbc02f7..2cacd2d 100644 --- a/deephaven_ipywidgets/tests/test_table.py +++ b/deephaven_ipywidgets/tests/test_table.py @@ -19,5 +19,5 @@ def test_example_creation_blank(MockTableClass): mock_table.__class__.__module__ = 'deephaven.table' mock_table.__class__.__name__ = 'Table' w = DeephavenWidget(mock_table) - assert w.server_url == 'http://localhost:9876' + assert w.server_url == 'http://localhost:9876/' assert str(w.iframe_url).startswith('http://localhost:9876/iframe/table/?name=t_')