Skip to content

Commit

Permalink
[Visualization] Clean up full.tpl to improve vis loading time (#3116)
Browse files Browse the repository at this point in the history
* Remove @jupyter/html-manager from full.tpl

* Include visualization server cloudbuild yaml to facilitate local dev

* Stop fallback behavior of KFP UI to improve dev experience
  • Loading branch information
Bobgy authored Feb 19, 2020
1 parent 23e9d37 commit 842b0ce
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
2 changes: 1 addition & 1 deletion backend/src/apiserver/visualization/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,5 @@ def generate_html_from_notebook(self, nb: NotebookNode) -> Text:
# Output generator
self.ep.preprocess(nb, {"metadata": {"path": Path.cwd()}}, self.km)
# Export all html and outputs
body, _ = html_exporter.from_notebook_node(nb)
body, _ = html_exporter.from_notebook_node(nb, resources={})
return body
29 changes: 2 additions & 27 deletions backend/src/apiserver/visualization/templates/full.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>

{% block ipywidgets %}
{%- if "widgets" in nb.metadata -%}
<script>
(function() {
function addWidgetsRenderer() {
var mimeElement = document.querySelector('script[type="application/vnd.jupyter.widget-view+json"]');
var scriptElement = document.createElement('script');
var widgetRendererSrc = '{{ resources.ipywidgets_base_url }}@jupyter-widgets/html-manager@*/dist/embed-amd.js';
var widgetState;
// Fallback for older version:
try {
widgetState = mimeElement && JSON.parse(mimeElement.innerHTML);
if (widgetState && (widgetState.version_major < 2 || !widgetState.version_major)) {
widgetRendererSrc = '{{ resources.ipywidgets_base_url }}jupyter-js-widgets@*/dist/embed.js';
}
} catch(e) {}
scriptElement.src = widgetRendererSrc;
document.body.appendChild(scriptElement);
}
document.addEventListener('DOMContentLoaded', addWidgetsRenderer);
}());
</script>
{%- endif -%}
<!-- TODO: integrate this back, background: https://github.com/kubeflow/pipelines/issues/3114#issuecomment-588071746 -->
{% endblock ipywidgets %}

{% for css in resources.inlining.css -%}
Expand Down Expand Up @@ -98,4 +73,4 @@ div#notebook-container{
{% block footer %}
{{ super() }}
</html>
{% endblock footer %}
{% endblock footer %}
3 changes: 0 additions & 3 deletions frontend/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,5 @@ function createUIServer(options: UIConfigs) {
app.use(basePath, StaticHandler(options.server.staticDir));
app.use(StaticHandler(options.server.staticDir));

/** Fallback to index.html */
app.get('*', indexHtmlHandler);

return app;
}
8 changes: 8 additions & 0 deletions test/cloudbuild/visualization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- id: "visualization-server"
name: "gcr.io/cloud-builders/docker"
args:
["build", "-t", "$_GCR_BASE/visualization-server", "-f", "backend/Dockerfile.visualization", "."]
images:
- "$_GCR_BASE/visualization-server"
timeout: 1800s # 30min

0 comments on commit 842b0ce

Please sign in to comment.