Skip to content

Make reusing voila easier with custom template + gridstack example#14

Merged
SylvainCorlay merged 9 commits intovoila-dashboards:masterfrom
maartenbreddels:reuse
Nov 19, 2018
Merged

Make reusing voila easier with custom template + gridstack example#14
SylvainCorlay merged 9 commits intovoila-dashboards:masterfrom
maartenbreddels:reuse

Conversation

@maartenbreddels
Copy link
Copy Markdown
Member

Using, e.g.:

$ voila examples/dashboard-grid/dashboard.ipynb  --custom_path=examples/dashboard-grid 

Will add the examples/dashboard-grid to the searchpath of the templates. It will also add new static file handers for:

  • /voila/custom/(js|css|vendor)

To make this possible/easier voila.tpl got renamed to base.html (and refactored a bit). The default template is now voila.html, which extends base.html.

The added example adds a custom template that uses gridstack.js to render the (non-empty) outputs of codecells and markdown to tiles:
screen shot 2018-11-06 at 15 29 03

Tiles size can be configured using cell metadata:
screen shot 2018-11-06 at 15 36 48

Screencap:
screencap-voila-gridstack

@timkpaine
Copy link
Copy Markdown
Member

@maartenbreddels this is awesome!

@maartenbreddels
Copy link
Copy Markdown
Member Author

Thanks Tim!

@SylvainCorlay
Copy link
Copy Markdown
Member

cc @ellisonbg @parente
at this point this is just an example of using a custom template for voila, although it triggers the question of the cell metadata spec.

Do you guys have more info, pointers on the spec that was used for the jupyter dashboards?

https://github.com/jupyter/dashboards/blob/0.7.0/jupyter_dashboards/nbextension/notebook/dashboard-view/dashboard-metadata.js

@parente
Copy link
Copy Markdown

parente commented Nov 7, 2018

We doc'ed the spec we used in jupyter_dashboards here: https://jupyter-dashboards-layout.readthedocs.io/en/latest/metadata.html

Most of the discussion was about how it was too limited to be part of the official schema (which makes sense) and how additional layouts, display formats, media types, etc. were desirable (lots over here: jupyterlab/jupyterlab#1640)

@SylvainCorlay
Copy link
Copy Markdown
Member

Thanks @parente !

@maartenbreddels
Copy link
Copy Markdown
Member Author

Thanks @parente for the info.
@SylvainCorlay I think we can merge this, I think we can just see this as an example, following those specs is another project on its own.

Comment thread js/webpack.config.js Outdated
@SylvainCorlay
Copy link
Copy Markdown
Member

Still working on it. Will be merged later today or tomorrow.

@SylvainCorlay
Copy link
Copy Markdown
Member

Pushed a few changes.

To specify the custom template path:

voila dashboard-grid/dashboard.ipynb --custom_template_path=dashboard-grid

@SylvainCorlay
Copy link
Copy Markdown
Member

I would have liked the custom_template_path to be a configurable of the VoilaHandler instead of the voila app, so that we can set this up in the same way with both the server extension and the app.

Unfortunately, handlers are not traitlet configurables. Maybe we could make mixins so that they are. @minrk might have an opinion on that.

Another way to pass these options to the server extension would be to do something like

diff --git a/voila/server_extension.py b/voila/server_extension.py
index 2e516e8..3f8c2ff 100644
--- a/voila/server_extension.py
+++ b/voila/server_extension.py
@@ -20,6 +20,11 @@ from .paths import ROOT, TEMPLATE_ROOT, STATIC_ROOT
 from .handler import VoilaHandler
 from .treehandler import VoilaTreeHandler
 
+voila_handler_options = {
+    'strip_sources': True,
+    'custom_template_path': None
+}
+
 def load_jupyter_server_extension(server_app):
     web_app = server_app.web_app
 
@@ -33,7 +38,7 @@ def load_jupyter_server_extension(server_app):
     host_pattern = '.*$'
     base_url = url_path_join(web_app.settings['base_url'])
     web_app.add_handlers(host_pattern, [
-        (url_path_join(base_url, '/voila/render' + path_regex), VoilaHandler),
+        (url_path_join(base_url, '/voila/render' + path_regex), VoilaHandler, voila_handler_options),
         (url_path_join(base_url, '/voila'), VoilaTreeHandler),
         (url_path_join(base_url, '/voila/tree' + path_regex), VoilaTreeHandler),
         (url_path_join(base_url, '/voila/static/(.*)'),  tornado.web.StaticFileHandler, {'path': str(STATIC_ROOT)})

and make this voila_handler_options be a configurable thing...

@SylvainCorlay SylvainCorlay merged commit 3b12e8d into voila-dashboards:master Nov 19, 2018
@maartenbreddels
Copy link
Copy Markdown
Member Author

Looking good!

@jtpio
Copy link
Copy Markdown
Member

jtpio commented Jan 16, 2019

@SylvainCorlay that would be great to have for the server extension too.

How about adding the folder containing the notebook as one of the search paths in template_path? So the voila.tpl file can be directly placed next to the notebook.

@SylvainCorlay
Copy link
Copy Markdown
Member

Hey @jtpio that may be a good idea for the nbconvert templates!

Note that we don't want to serve the notebook directory though, for reasons explained in #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants