Skip to content

Commit 1b4aa81

Browse files
committed
Add --window_title flag.
1 parent f5dec9c commit 1b4aa81

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

tensorboard/backend/application.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def standard_tensorboard_wsgi(
7979
plugins,
8080
db_uri="",
8181
assets_zip_provider=None,
82-
path_prefix=""):
82+
path_prefix="",
83+
window_title=""):
8384
"""Construct a TensorBoardWSGIApp with standard plugins and multiplexer.
8485
8586
Args:
@@ -95,6 +96,7 @@ def standard_tensorboard_wsgi(
9596
If this value is not specified, this function will attempt to load
9697
the `tensorboard.default` module to use the default. This behavior
9798
might be removed in the future.
99+
window_title: A string specifying the the window title.
98100
99101
Returns:
100102
The new TensorBoard WSGI application.
@@ -119,7 +121,8 @@ def standard_tensorboard_wsgi(
119121
logdir=logdir,
120122
multiplexer=multiplexer,
121123
assets_zip_provider=assets_zip_provider,
122-
plugin_name_to_instance=plugin_name_to_instance)
124+
plugin_name_to_instance=plugin_name_to_instance,
125+
window_title=window_title)
123126
plugin_instances = [constructor(context) for constructor in plugins]
124127
for plugin_instance in plugin_instances:
125128
plugin_name_to_instance[plugin_instance.plugin_name] = plugin_instance

tensorboard/components/tf_backend/router.ts

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Router {
1818
logdir: () => string;
1919
runs: () => string;
2020
pluginsListing: () => string;
21+
windowProperties: () => string;
2122
isDemoMode: () => boolean;
2223
pluginRoute: (pluginName: string, route: string) => string;
2324
}
@@ -47,6 +48,7 @@ export function createRouter(dataDir = 'data', demoMode = false): Router {
4748
logdir: () => dataDir + '/logdir',
4849
runs: () => dataDir + '/runs' + (demoMode ? '.json' : ''),
4950
pluginsListing: () => dataDir + '/plugins_listing',
51+
windowProperties: () => dataDir + '/window_properties',
5052
isDemoMode: () => demoMode,
5153
pluginRoute,
5254
};

tensorboard/components/tf_tensorboard/tf-tensorboard.html

+10
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
669669
'dom-change', onDomChange, /*useCapture=*/false);
670670

671671
tf_backend.fetchRuns();
672+
this._fetchWindowProperties();
672673
this._fetchLogdir();
673674
this._fetchActiveDashboards();
674675
this._lastReloadTime = new Date().toString();
@@ -706,6 +707,15 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
706707
.then(updateActiveDashboards, onFailure);
707708
},
708709

710+
_fetchWindowProperties() {
711+
const url = tf_backend.getRouter().windowProperties();
712+
return this._requestManager.request(url).then(result => {
713+
if (result.window_title) {
714+
window.document.title = result.window_title;
715+
}
716+
});
717+
},
718+
709719
_computeActiveDashboardsNotLoaded(state) {
710720
return state === tf_tensorboard.ActiveDashboardsLoadState.NOT_LOADED;
711721
},

tensorboard/plugins/base_plugin.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def __init__(
8888
db_module=None,
8989
logdir=None,
9090
multiplexer=None,
91-
plugin_name_to_instance=None):
91+
plugin_name_to_instance=None,
92+
window_title=None):
9293
"""Instantiates magic container.
9394
9495
The argument list is sorted and may be extended in the future; therefore,
@@ -120,10 +121,12 @@ def __init__(
120121
plugin may be absent from this mapping until it is registered. Plugin
121122
logic should handle cases in which a plugin is absent from this
122123
mapping, lest a KeyError is raised.
124+
window_title: A string specifying the the window title.
123125
"""
124126
self.assets_zip_provider = assets_zip_provider
125127
self.db_connection_provider = db_connection_provider
126128
self.db_module = db_module
127129
self.logdir = logdir
128130
self.multiplexer = multiplexer
129131
self.plugin_name_to_instance = plugin_name_to_instance
132+
self.window_title = window_title

tensorboard/plugins/core/core_plugin.py

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self, context):
4848
context: A base_plugin.TBContext instance.
4949
"""
5050
self._logdir = context.logdir
51+
self._window_title = context.window_title
5152
self._multiplexer = context.multiplexer
5253
self._assets_zip_provider = context.assets_zip_provider
5354

@@ -60,6 +61,7 @@ def get_plugin_apps(self):
6061
'/audio': self._redirect_to_index,
6162
'/data/logdir': self._serve_logdir,
6263
'/data/runs': self._serve_runs,
64+
'/data/window_properties': self._serve_window_properties,
6365
'/events': self._redirect_to_index,
6466
'/favicon.ico': self._send_404_without_logging,
6567
'/graphs': self._redirect_to_index,
@@ -97,6 +99,12 @@ def _serve_logdir(self, request):
9799
return http_util.Respond(
98100
request, {'logdir': self._logdir}, 'application/json')
99101

102+
@wrappers.Request.application
103+
def _serve_window_properties(self, request):
104+
"""Serve a JSON object containing this TensorBoard's window properties."""
105+
return http_util.Respond(
106+
request, {'window_title': self._window_title}, 'application/json')
107+
100108
@wrappers.Request.application
101109
def _serve_runs(self, request):
102110
"""WSGI app serving a JSON object about runs and tags.

tensorboard/program.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@
118118
'based routing of an elb when the website base_url is not available '
119119
'e.g. "example.site.com/path/to/tensorboard/"')
120120

121+
tf.flags.DEFINE_string(
122+
'window_title', '',
123+
'The title of the browser window.')
124+
121125
FLAGS = tf.flags.FLAGS
122126

123127

@@ -191,7 +195,8 @@ def create_tb_app(plugins, assets_zip_provider=None):
191195
purge_orphaned_data=FLAGS.purge_orphaned_data,
192196
reload_interval=FLAGS.reload_interval,
193197
plugins=plugins,
194-
path_prefix=FLAGS.path_prefix)
198+
path_prefix=FLAGS.path_prefix,
199+
window_title=FLAGS.window_title)
195200

196201

197202
def make_simple_server(tb_app, host=None, port=None, path_prefix=None):

0 commit comments

Comments
 (0)