Skip to content
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

Support jupyter-server-proxy (and other proxies) #3674

Merged
merged 7 commits into from
Jun 3, 2020
20 changes: 16 additions & 4 deletions tensorboard/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import datetime
import errno
import json
import os
import random
import shlex
import sys
Expand Down Expand Up @@ -378,18 +379,29 @@ def _display_ipython(port, height, display_handle):
<script>
(function() {
const frame = document.getElementById(%JSON_ID%);
const url = new URL("/", window.location);
url.port = %PORT%;
const url = new URL("%ABS_PATH%", window.location);
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
%PORT_CHANGE%
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
frame.src = url;
})();
</script>
"""
"""
replacements = [
("%HTML_ID%", html_escape(frame_id, quote=True)),
("%JSON_ID%", json.dumps(frame_id)),
("%PORT%", "%d" % port),
("%HEIGHT%", "%d" % height),
]
if "TENSORBOARD_PROXY_URL" in os.environ:
abs_path = os.environ["TENSORBOARD_PROXY_URL"]
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
# Allow %PORT% in $TENSORBOARD_PROXY_URL
abs_path = abs_path.replace("%PORT%", "%d" % port)
replacements.extend(
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
[("%ABS_PATH%", abs_path), ("%PORT_CHANGE%", ""),]
)
else:
replacements.extend(
[("%ABS_PATH%", "/"), ("%PORT_CHANGE%", "url.port = %d;" % port),]
)

for (k, v) in replacements:
shell = shell.replace(k, v)
iframe = IPython.display.HTML(shell)
Expand Down