Skip to content

Commit

Permalink
adding ipy url (#12)
Browse files Browse the repository at this point in the history
Fixes #10
Verified by creating a docker container:

docker run -p 10000:8888 -p 8080:1234 ghcr.io/deephaven/deephaven-kube-demo-worker-jupyter:main
Then running the following code in a jupyter notebook in the docker container:

from deephaven_server import Server

s = Server(port=1234, jvm_args=["-Xmx10g"])
s.start()

from deephaven_ipywidgets import DeephavenWidget
from deephaven.plot.figure import Figure
from deephaven import empty_table
from deephaven import time_table
from deephaven import ugp

static_table = empty_table(100).update(["X = i", "Y = Math.sin(0.1 * X)"])

import os
os.environ['DEEPHAVEN_IPY_URL'] = "http://localhost:8080/"

static_widget = DeephavenWidget(static_table)
display(static_widget)
  • Loading branch information
jnumainville authored Apr 10, 2023
1 parent ee39e19 commit 5c08c84
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion deephaven_ipywidgets/deephaven.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from deephaven_server import Server
from uuid import uuid4
from ._frontend import module_name, module_version

import os

def _str_object_type(obj):
"""Returns the object type as a string value"""
Expand Down Expand Up @@ -63,14 +63,21 @@ def __init__(self, deephaven_object, height=600, width=0):
object_id = f"t_{str(uuid4()).replace('-', '_')}"

port = Server.instance.port

server_url = f"http://localhost:{Server.instance.port}/"

if "DEEPHAVEN_IPY_URL" in os.environ:
server_url = os.environ["DEEPHAVEN_IPY_URL"]

try:
from google.colab.output import eval_js
server_url = eval_js(f"google.colab.kernel.proxyPort({port})")
except ImportError:
pass

if not server_url.endswith("/"):
server_url = f"{server_url}/"

# Generate the iframe_url from the object type
iframe_url = f"{server_url}iframe/{_path_for_object(deephaven_object)}/?name={object_id}"

Expand Down

0 comments on commit 5c08c84

Please sign in to comment.