Customizing Voilà

There are many ways you can customize Voilà to control the look and feel of the dashboards you create.

Changing the theme

By default, Voilà uses the light theme, but you can set the theme to dark by passing the following option:

voila <path-to-notebook> --theme=dark

Or by passing in the query parameter voila-theme, e.g. a URL like http://localhost:8867/voila/render/query-strings.ipynb?voila-theme=dark.

The theme can also be set in the notebook metadata, under metadata/voila/theme by editing the notebook file manually, or using the metadata editor in for instance the classical notebook

Edit metadata

System administrators who want to disable changing the theme, can pass --VoilaConfiguration.allow_theme_override=NO or --VoilaConfiguration.allow_theme_override=NOTEBOOK to disable changing the theme completely, or only allow it from the notebook metadata.

Currently, Voilà supports only light and dark themes.


Changing the theme from the notebook metadata may change in the future if this features moves to nbconvert.

Controlling the nbconvert template

Voilà uses nbconvert to convert your Jupyter Notebook into an HTML dashboard. nbconvert has a rich templating system that allows you to customize the way in which your Jupyter Notebook is converted into HTML.

By default, Voilà will render the HTML from your notebook in the same linear fashion that the notebook follows. If you’d like to use a different layout, this can be controlled by creating a new nbconvert template, registering it with Voilà, and calling it from the command-line like so:

voila <path-to-notebook> --template=<name-of-template>

For example, Voilà includes one other template that uses a Javascript library and an alternate <div> layout in order to let the user drag and drop cells.

For example, to use the gridstack template, use the command:

voila <path-to-notebook> --template=gridstack

Or by passing in the query parameter voila-template, e.g. a URL like http://localhost:8867/voila/render/query-strings.ipynb?voila-template=material (Note that this requires installing voila-material).

The template can also set in the notebook metadata, under metadata/voila/template by editing the notebook file manually, or using the metadata editor in for instance the classical notebook

Edit metadata

System administrators who want to disable changing the theme, can pass --VoilaConfiguration.allow_template_override=NO` or ``--VoilaConfiguration.allow_template_override=NOTEBOOK to disable changing the theme completely, or only allow it from the notebook metadata.


Changing the template from the notebook metadata may change in the future if this features moves to nbconvert.

Creating your own template

You can create your own nbconvert template for use with Voilà. This allows you to control the look and feel of your dashboard.

In order to create your own template, first familiarize yourself with Jinja, HTML, and CSS. Each of these is used in creating custom templates. For more information, see the nbconvert templates documentation. For one example, check out the nbconvert basic HTML template.

A few example voila/nbconvert template projects are:

Where are Voilà templates located?

All Voilà templates are stored as folders with particular configuration/template files inside. These folders can exist in the standard Jupyter configuration locations, in a folder called voila/templates. For example:


Voilà will search these locations for a folder, one per template, where the folder name defines the template name.

The Voilà template structure

Within each template folder, you can provide your own nbconvert templates, static files, and HTML templates (for pages such as a 404 error). For example, here is the folder structure of the base Voilà template (called “default”):

tree path/to/env/share/jupyter/voila/templates/default/
├── nbconvert_templates
│   ├── base.tpl
│   └── voila.tpl
└── templates
    ├── 404.html
    ├── error.html
    ├── page.html
    └── tree.html

To customize the nbconvert template, store it in a folder called templatename/nbconvert_templates/voila.tpl. In the case of the default template, we also provide a base.tpl that our custom template uses as a base. The name voila.tpl is special - you cannot name your custom nbconvert something else.

To customize the HTML page templates, store them in a folder called templatename/templates/<name>.html. These are files that Voilà can serve as standalone HTML (for example, the tree.html template defines how folders/files are displayed in localhost:8866/voila/tree). You can override the defaults by providing your own HTML files of the same name.

To configure your Voilà template, you should add a config.json file to the root of your template folder.

An example custom template

To show how to create your own custom template, let’s create our own nbconvert template. We’ll have two goals:

  1. Add an <h1> header displaying “Our awesome template” to the Voilà dashboard.

  2. Add a custom 404.html page that displays an image.

First, we’ll create a folder in ~/.local/share/jupyter/voila/templates called mytemplate:

mkdir ~/.local/share/jupyter/voila/templates/mytemplate
cd ~/.local/share/jupyter/voila/templates/mytemplate

Next, we’ll copy over the base template files for Voilà, which we’ll modify:

cp -r path/to/env/share/jupyter/voila/templates/default/nbconvert_templates ./
cp -r path/to/env/share/jupyter/voila/templates/default/templates ./

We should now have a folder structure like this:

tree .
├── nbconvert_templates
│   ├── base.tpl
│   └── voila.tpl
└── templates
    ├── 404.html
    ├── error.html
    ├── page.html
    └── tree.html

Now, we’ll edit nbconvert_templates/voila.tpl to include a custom H1 header.

As well as templates/tree.html to include an image.

Finally, we can tell Voilà to use this custom template the next time we use it on a Jupyter notebook by using the name of the folder in the --template parameter:

voila mynotebook.ipynb --template=mytemplate

The result should be a Voilà dashboard with your custom modifications made!

Voilà template cookiecutter

There is a Voilà template cookiecutter available to give you a running start. This cookiecutter contains some docker configuration for live reloading of your template changes to make development easier. Please refer to the cookiecutter repo for more information on how to use the Voilà template cookiecutter.

Adding your own static files

If you create your own theme, you may also want to define and use your own static files, such as CSS and Javascript. To use your own static files, follow these steps:

  1. Create a folder along with your template (e.g., mytemplate/static/).

  2. Put your static files in this template.

  3. In your template file (e.g. voila.tpl), link these static files with the following path:

  4. When you call voila, configure the static folder by using the --static kwarg, or by configuring --VoilaConfiguration.static_root.

Any folders / files that are inside the folder given with this configuration will be copied to {{resources.base_url}}voila/static/.

For example, if you had a CSS file called custom.css in static/css, you would link it in your template like so:

<link rel="stylesheet" type="text/css" href="{{resources.base_url}}voila/static/css/custom.css"></link>

Configure Voilà for the Jupyter Server

Several pieces of voila’s functionality can be controlled when it is run. This can be done either as a part of the standalone CLI, or with the Jupyter Server. To configure voila when run by the Jupyter Server, use the following pattern when invoking the command that runs Jupyter (e.g., Jupyter Lab or Jupyter Notebook):

<jupyter-command> --VoilaConfiguration.<config-key>=<config-value>

For example, to control the template used by voila from within a Jupyter Lab session, use the following command when starting the server:

jupyter lab --VoilaConfiguration.template=distill

When users run voila by hitting the voila/ endpoint, this configuration will be used.

Serving static files

Unlike JupyterLab or the classic notebook server, voila does not serve all files that are present in the directory of the notebook. Only files that match one of the whitelists and none of the blacklist regular expression are served by Voilà:

voila mydir --VoilaConfiguration.file_whitelist="['.*']" \
  --VoilaConfiguration.file_blacklist="['private.*', '.*\.(ipynb)']"

Which will serve all files, except anything starting with private, or notebook files:

voila mydir --VoilaConfiguration.file_whitelist="['.*\.(png|jpg|gif|svg|mp4|avi|ogg)']"

Will serve many media files, and also never serve notebook files (which is the default blacklist).

Run scripts

Voilà can run text (or script) files, by configuring how a file extension maps to a kernel language:

voila mydir --VoilaConfiguration.extension_language_mapping='{".py": "python", ".jl": "julia"}'

Voilà will find a kernel that matches the language specified, but can also be configured to use a specific kernel for each language:

voila mydir --VoilaConfiguration.extension_language_mapping='{".py": "python", ".jl": "julia"}'\
  --VoilaConfiguration.language_kernel_mapping='{"python": "xpython"}'

In this case it will use the xeus-python. kernel to run .py files.

Note that the script will be executed as notebook with a single cell, meaning that only the last expression will be printed as output. Use the Jupyter display mechanism to output any text or rich output such as Jupyter widgets. For Python this would be a call to IPython.display.display.

Using Jupytext is another way to support script files. After installing jupytext, Voilà will see script files as if they are notebooks, and requires no extra configuration.

Cull idle kernels

Voilà starts a new Jupyter kernel every time a notebook is rendered to the user. In some situations, this can lead to a higher memory consumption.

The Jupyter Server exposes several options that can be used to terminate kernels that are not active anymore. They can be configured using the Voilà standalone app:

voila --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120

The server will periodically check for idle kernels, in this example every 60 seconds, and cull them if they have been idle for more than 120 seconds.

The same parameters apply when using Voilà as a server extension:

jupyter notebook --MappingKernelManager.cull_interval=60 --MappingKernelManager.cull_idle_timeout=120

There is also the MappingKernelManager.cull_busy and MappingKernelManager.cull_connected options to cull busy kernels and kernels with an active connection.

For more information about these options, check out the Jupyter Server documentation.

Hiding output and code cells based on cell tags

Voilà uses nbconvert under the hood to render the notebooks so we can benefit from some of its advanced functionalities to hide code and output cells based on cell tags.

To hide the cell output for every cell in your notebook that has been tagged (how to tag) with “hide” in Voilà:

voila --TagRemovePreprocessor.remove_all_outputs_tags='{"hide"}' your_notebook.ipynb

To hide both the code cell and the output cell (if any) for every cell that has been tagged with “hide”:

voila --TagRemovePreprocessor.remove_cell_tags='{"hide"}' your_notebook.ipynb

You can use any tag you want but be sure to use the same tag name in the Voilà command. And please note that this functionality will only hide the cells in Voilà but will not prevent them from being executed.

Cell execution timeouts

By default, Voilà does not have an execution timeout, meaning there is no limit for how long it takes for Voilà to execute and render your notebook. If you have potentially long-running cells, you may wish to set a cell execution timeout so that users of your dashboard will get an error if it takes longer than expected to execute the notebook. For example:

voila --VoilaExecutor.timeout=30 your_notebook.ipynb

With this setting, if any cell takes longer than 30 seconds to run, a TimeoutError will be raised. You can further customize this behavior using the VoilaExecutor.timeout_func and VoilaExecutor.interrupt_on_timeout options.