Best practice for menu and lazy loading

Hi All… can you help with the best practices for setting up a menu in Panel where the dashboard is loaded ONLY when that particular menu item is selected/clicked? I have currently set up a tab based page but that loads all the dashboards in question and that’s a huge hit on front-end performance as well as the server load.

1 Like

Hi @chrisj

Have you tried using the dynamic=True argument of Tabs? That will only load the tab displayed.

Tabs Reference Guide

1 Like

More specifically try lazy ParamFunction approach outlined in the Tabs reference guide:

import time
import numpy as np

def plot():
    time.sleep(1) # some long running calculation
    np.random.seed(tabs.active)
    xs, ys = np.random.randn(2, 100)
    p = figure(width=300, height=300, name=f'Scatter Seed {tabs.active}')
    p.scatter(xs, ys)
    return p

p1 = pn.param.ParamFunction(plot, lazy=True, name='Seed 0')
p2 = pn.param.ParamFunction(plot, lazy=True, name='Seed 1')
p3 = pn.param.ParamFunction(plot, lazy=True, name='Seed 2')

tabs = pn.Tabs(p1, p2, p3, dynamic=True)

tabs
1 Like

Thanks for all the suggestions… i have to park this for now, will get back to it next week.

1 Like