panel icon indicating copy to clipboard operation
panel copied to clipboard

FastListTemplate().save() throws an exception

Open tomascsantos opened this issue 5 months ago • 2 comments

ALL software version info

param==2.0.1 panel==1.3.4 Jinja2==3.1.2 bokeh==3.3.1

Description of expected behavior and the observed behavior

Calling save on a panel object should save a file of the object

Complete, minimal, self-contained example code that reproduces the issue

import panel as pn

pn.extension(sizing_mode='stretch_width')

app = pn.template.FastListTemplate(
    main=pn.Column('hello world'),
    sidebar=pn.Column('sidebar'),
    title='My title',
).save('test.html')

Stack traceback and/or browser JavaScript console output

(paneltools-dev) ➜  test-save git:(tomas-test-save) ✗ python app.py
Traceback (most recent call last):
  File "/Users/tcastrosantos/Documents/dashboard-portal/dashboards/fleet-analytics/test-save/app.py", line 5, in <module>
    app = pn.template.FastListTemplate(
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/panel/template/base.py", line 451, in save
    return save(
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/panel/io/save.py", line 290, in save
    html = file_html(doc, resources, title, **kwargs)
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/panel/io/save.py", line 164, in file_html
    return html_page_for_render_items(
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/bokeh/embed/elements.py", line 145, in html_page_for_render_items
    html = template.render(context)
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/panel/template/fast/list/fast_list_template.html", line 1, in top-level template code
    {% extends base %}
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/bokeh/core/_templates/file.html", line 47, in top-level template code
    {% block body %}
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/bokeh/core/_templates/file.html", line 49, in block 'body'
    {%  block inner_body %}
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/bokeh/core/_templates/file.html", line 50, in block 'inner_body'
    {%    block contents %}
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/panel/template/fast/list/fast_list_template.html", line 176, in block 'contents'
    <div class="card-margin {{ sizing_modes[root.id] }}">
  File "/opt/anaconda3/envs/paneltools-dev/lib/python3.9/site-packages/jinja2/environment.py", line 466, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'sizing_modes' is undefined

tomascsantos avatar Jan 02 '24 17:01 tomascsantos

We are seeing the same issue with panel==1.3.8. Any suggested workarounds?

l3ender avatar Jan 27 '24 22:01 l3ender

I was able to get past the error by using the static/module method instead of the one on the panel/template itself.

https://panel.holoviz.org/api/panel.io.html#panel.io.save.save

import panel.io.save as pnsave
pnsave.save(panel=app, filename='test.html')

l3ender avatar Jan 28 '24 01:01 l3ender

+1

I experience same issue as Tomas. The workaround described by I3ender does not work for me with the FastListTemplate.

MarcSkovMadsen avatar Mar 01 '24 13:03 MarcSkovMadsen