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
36 changes: 27 additions & 9 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,35 @@ 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(%URL%, window.location);
const port = %PORT%;
if (port) {
zac-hopkinson marked this conversation as resolved.
Show resolved Hide resolved
url.port = port;
}
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),
]
"""
proxy_url = os.environ.get("TENSORBOARD_PROXY_URL")
if proxy_url is not None:
# Allow %PORT% in $TENSORBOARD_PROXY_URL
proxy_url = proxy_url.replace("%PORT%", "%d" % port)
replacements = [
("%HTML_ID%", html_escape(frame_id, quote=True)),
("%JSON_ID%", json.dumps(frame_id)),
("%HEIGHT%", "%d" % height),
("%PORT%", "0"),
("%URL%", json.dumps(proxy_url)),
]
else:
replacements = [
("%HTML_ID%", html_escape(frame_id, quote=True)),
("%JSON_ID%", json.dumps(frame_id)),
("%HEIGHT%", "%d" % height),
("%PORT%", "%d" % port),
("%URL%", json.dumps("/")),
]

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