From 3a1bb52c69413cd69b2b67b8d7d3a353742ec68d Mon Sep 17 00:00:00 2001 From: Toni Kunic Date: Mon, 11 Dec 2017 15:20:46 -0500 Subject: [PATCH] Add --window_title flag. (#804) --- tensorboard/backend/application.py | 7 +++++-- tensorboard/components/tf_backend/router.ts | 2 ++ .../components/tf_tensorboard/tf-tensorboard.html | 10 ++++++++++ tensorboard/plugins/base_plugin.py | 5 ++++- tensorboard/plugins/core/core_plugin.py | 8 ++++++++ tensorboard/program.py | 7 ++++++- 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/tensorboard/backend/application.py b/tensorboard/backend/application.py index 86b199fa77..67cbc3331e 100644 --- a/tensorboard/backend/application.py +++ b/tensorboard/backend/application.py @@ -79,7 +79,8 @@ def standard_tensorboard_wsgi( plugins, db_uri="", assets_zip_provider=None, - path_prefix=""): + path_prefix="", + window_title=""): """Construct a TensorBoardWSGIApp with standard plugins and multiplexer. Args: @@ -95,6 +96,7 @@ def standard_tensorboard_wsgi( If this value is not specified, this function will attempt to load the `tensorboard.default` module to use the default. This behavior might be removed in the future. + window_title: A string specifying the the window title. Returns: The new TensorBoard WSGI application. @@ -119,7 +121,8 @@ def standard_tensorboard_wsgi( logdir=logdir, multiplexer=multiplexer, assets_zip_provider=assets_zip_provider, - plugin_name_to_instance=plugin_name_to_instance) + plugin_name_to_instance=plugin_name_to_instance, + window_title=window_title) plugin_instances = [constructor(context) for constructor in plugins] for plugin_instance in plugin_instances: plugin_name_to_instance[plugin_instance.plugin_name] = plugin_instance diff --git a/tensorboard/components/tf_backend/router.ts b/tensorboard/components/tf_backend/router.ts index 2e94323e84..07d0ea10bd 100644 --- a/tensorboard/components/tf_backend/router.ts +++ b/tensorboard/components/tf_backend/router.ts @@ -18,6 +18,7 @@ export interface Router { logdir: () => string; runs: () => string; pluginsListing: () => string; + windowProperties: () => string; isDemoMode: () => boolean; pluginRoute: (pluginName: string, route: string) => string; } @@ -47,6 +48,7 @@ export function createRouter(dataDir = 'data', demoMode = false): Router { logdir: () => dataDir + '/logdir', runs: () => dataDir + '/runs' + (demoMode ? '.json' : ''), pluginsListing: () => dataDir + '/plugins_listing', + windowProperties: () => dataDir + '/window_properties', isDemoMode: () => demoMode, pluginRoute, }; diff --git a/tensorboard/components/tf_tensorboard/tf-tensorboard.html b/tensorboard/components/tf_tensorboard/tf-tensorboard.html index e22977e6dd..b65a83703a 100644 --- a/tensorboard/components/tf_tensorboard/tf-tensorboard.html +++ b/tensorboard/components/tf_tensorboard/tf-tensorboard.html @@ -669,6 +669,7 @@

There’s no dashboard by the name of “[[_selectedDashboard]].” 'dom-change', onDomChange, /*useCapture=*/false); tf_backend.fetchRuns(); + this._fetchWindowProperties(); this._fetchLogdir(); this._fetchActiveDashboards(); this._lastReloadTime = new Date().toString(); @@ -706,6 +707,15 @@

There’s no dashboard by the name of “[[_selectedDashboard]].” .then(updateActiveDashboards, onFailure); }, + _fetchWindowProperties() { + const url = tf_backend.getRouter().windowProperties(); + return this._requestManager.request(url).then(result => { + if (result.window_title) { + window.document.title = result.window_title; + } + }); + }, + _computeActiveDashboardsNotLoaded(state) { return state === tf_tensorboard.ActiveDashboardsLoadState.NOT_LOADED; }, diff --git a/tensorboard/plugins/base_plugin.py b/tensorboard/plugins/base_plugin.py index 4287ee45b1..24ddacd645 100644 --- a/tensorboard/plugins/base_plugin.py +++ b/tensorboard/plugins/base_plugin.py @@ -88,7 +88,8 @@ def __init__( db_module=None, logdir=None, multiplexer=None, - plugin_name_to_instance=None): + plugin_name_to_instance=None, + window_title=None): """Instantiates magic container. The argument list is sorted and may be extended in the future; therefore, @@ -120,6 +121,7 @@ def __init__( plugin may be absent from this mapping until it is registered. Plugin logic should handle cases in which a plugin is absent from this mapping, lest a KeyError is raised. + window_title: A string specifying the the window title. """ self.assets_zip_provider = assets_zip_provider self.db_connection_provider = db_connection_provider @@ -127,3 +129,4 @@ def __init__( self.logdir = logdir self.multiplexer = multiplexer self.plugin_name_to_instance = plugin_name_to_instance + self.window_title = window_title diff --git a/tensorboard/plugins/core/core_plugin.py b/tensorboard/plugins/core/core_plugin.py index 0ea9129ed8..18d593e432 100644 --- a/tensorboard/plugins/core/core_plugin.py +++ b/tensorboard/plugins/core/core_plugin.py @@ -48,6 +48,7 @@ def __init__(self, context): context: A base_plugin.TBContext instance. """ self._logdir = context.logdir + self._window_title = context.window_title self._multiplexer = context.multiplexer self._assets_zip_provider = context.assets_zip_provider @@ -60,6 +61,7 @@ def get_plugin_apps(self): '/audio': self._redirect_to_index, '/data/logdir': self._serve_logdir, '/data/runs': self._serve_runs, + '/data/window_properties': self._serve_window_properties, '/events': self._redirect_to_index, '/favicon.ico': self._send_404_without_logging, '/graphs': self._redirect_to_index, @@ -97,6 +99,12 @@ def _serve_logdir(self, request): return http_util.Respond( request, {'logdir': self._logdir}, 'application/json') + @wrappers.Request.application + def _serve_window_properties(self, request): + """Serve a JSON object containing this TensorBoard's window properties.""" + return http_util.Respond( + request, {'window_title': self._window_title}, 'application/json') + @wrappers.Request.application def _serve_runs(self, request): """WSGI app serving a JSON object about runs and tags. diff --git a/tensorboard/program.py b/tensorboard/program.py index 461eec74e4..c92c933915 100644 --- a/tensorboard/program.py +++ b/tensorboard/program.py @@ -118,6 +118,10 @@ 'based routing of an elb when the website base_url is not available ' 'e.g. "example.site.com/path/to/tensorboard/"') +tf.flags.DEFINE_string( + 'window_title', '', + 'The title of the browser window.') + FLAGS = tf.flags.FLAGS @@ -191,7 +195,8 @@ def create_tb_app(plugins, assets_zip_provider=None): purge_orphaned_data=FLAGS.purge_orphaned_data, reload_interval=FLAGS.reload_interval, plugins=plugins, - path_prefix=FLAGS.path_prefix) + path_prefix=FLAGS.path_prefix, + window_title=FLAGS.window_title) def make_simple_server(tb_app, host=None, port=None, path_prefix=None):