Skip to content

Commit

Permalink
Add --window_title flag. (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkunic authored and jart committed Dec 11, 2017
1 parent b3921ec commit 3a1bb52
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tensorboard/backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tensorboard/components/tf_backend/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Router {
logdir: () => string;
runs: () => string;
pluginsListing: () => string;
windowProperties: () => string;
isDemoMode: () => boolean;
pluginRoute: (pluginName: string, route: string) => string;
}
Expand Down Expand Up @@ -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,
};
Expand Down
10 changes: 10 additions & 0 deletions tensorboard/components/tf_tensorboard/tf-tensorboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
'dom-change', onDomChange, /*useCapture=*/false);

tf_backend.fetchRuns();
this._fetchWindowProperties();
this._fetchLogdir();
this._fetchActiveDashboards();
this._lastReloadTime = new Date().toString();
Expand Down Expand Up @@ -706,6 +707,15 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
.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;
},
Expand Down
5 changes: 4 additions & 1 deletion tensorboard/plugins/base_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -120,10 +121,12 @@ 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
self.db_module = db_module
self.logdir = logdir
self.multiplexer = multiplexer
self.plugin_name_to_instance = plugin_name_to_instance
self.window_title = window_title
8 changes: 8 additions & 0 deletions tensorboard/plugins/core/core_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion tensorboard/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 3a1bb52

Please sign in to comment.