Make reusing voila easier with custom template + gridstack example#14
Conversation
|
@maartenbreddels this is awesome! |
|
Thanks Tim! |
|
cc @ellisonbg @parente Do you guys have more info, pointers on the spec that was used for the jupyter dashboards? |
|
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) |
|
Thanks @parente ! |
|
Thanks @parente for the info. |
|
Still working on it. Will be merged later today or tomorrow. |
|
Pushed a few changes. To specify the custom template path: |
|
I would have liked the 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... |
|
Looking good! |
|
@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 |
Using, e.g.:
Will add the
examples/dashboard-gridto 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:

Tiles size can be configured using cell metadata:

Screencap:
