voila-dashboards / voila

Voilà turns Jupyter notebooks into standalone web applications
https://voila.readthedocs.io
Other
5.31k stars 497 forks source link

static files are not recognized when template is set in NB metadata #1464

Open dfguerrerom opened 2 months ago

dfguerrerom commented 2 months ago

Description

To set a custom voila template, there are two options:

see (https://github.com/voila-dashboards/voila/blob/7596c4f930caf4fc2d89ba63b1096046adf9fe0e/voila/app.py#L541)

Apparently, this bug mainly affects the static_paths, causing 404 errors in templates that uses them. I suspect it might also cause other, less noticible issues.

Reproduce

  1. create a simple notebook and set any other default template, for example: classic.
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "voila": {
    "template": "classic"
   }, 
  "language_info": {
   "name": "python",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
  1. launch voila voila --debug test.ipynb
  2. check the logs and notice:

First log shows "using lab template) image

Second log, (which is created by nbconvert and reads the notebook):

image

Expected behavior

The template should work when it is set in the notebook metadata.

Solution

If there's no time to address this error, I could open a PR but I would need some guidance, I think we could read the notebook in the setup_template_dirs (as a json file) and use the template name?