Save content of dynamic Tabs

Hello,

I’m using pn.Tabs(dynamic=True) in my application for showing a couple of plots. The option dynamic=True is necessary, otherwise my application no longer works smoothly when having 4-5 tabs.

I would like to export all the tabs with all the plots as html file. What happens now is that only the currently open tab is saved and the rest is ignores. Here is sample code and a gif showing the problem

import numpy as np
import holoviews as hv
import panel as pn
from io import StringIO
hv.extension('bokeh')

xs = np.linspace(0, np.pi*4, 40)
plot1 = hv.Area((xs, np.sin(xs)))
plot2 = hv.Area((xs, np.sin(xs))).opts(color="red")

tabs = pn.Tabs(plot1, plot2, dynamic=True)


def callback():
    sio = StringIO()
    tabs.save(sio, embed=True, resources="INLINE",)
    sio.seek(0)
    return sio

button = pn.widgets.FileDownload(label="Save", callback=callback, filename="file.html")

pn.Column(tabs, button).servable()

Is there a way to include all plots in all tabs in the html file?

Edit: my env: panel==0.10.3, holoviews==1.14.0, bokeh==2.2.3, python 3.7.10

Making them be non-dynamic during save should work:

def callback():
    sio = StringIO()
    tabs.clone(dynamic=False).save(sio, embed=True, resources="INLINE",)
    sio.seek(0)
    return sio
1 Like

Thank you, this solved my problem :slight_smile:

For future reference: I found that this may lead to another problem as described in this thread.