Yonghow,
Without a MRE it’s hard to test your specific issue.
I’ve asked a question on streaming recently, so it was pretty easy to update my MRE to work with the Multi page app documentation #3 example.
To run this MRE follow the steps in my question and use this version of app.py
import pandas as pd
import panel as pn
import hvplot.pandas
import holoviews as hv
from holoviews.streams import Buffer
from asyncio import sleep
pn.extension()
data = pn.state.cache["data"]
dfstream = Buffer(pd.DataFrame(data, index=[pd.Timestamp.now()]), length=100, index=False)
def plot(data, window_seconds, alpha):
data = data.rolling(f"{window_seconds}s").mean()
return data.hvplot(y="y", ylim=(-1, 1), alpha=alpha, color="blue", line_width=5)
window_seconds = pn.widgets.IntSlider(value=5, start=1, end=10, name="Window (secs)")
alpha = pn.widgets.FloatSlider(value=1, start=0, end=1, name="Alpha")
iplot = hv.DynamicMap(
plot,
streams={
"data": dfstream.param.data,
"window_seconds": window_seconds.param.value,
"alpha": alpha.param.value,
},
)
pages = {
"Page 1": pn.Column(iplot, window_seconds, alpha),
"Page 2": pn.Column("# Page 2", "...more bla"),
}
def show(page):
return pages[page]
starting_page = pn.state.session_args.get("page", [b"Page 1"])[0].decode()
page = pn.widgets.RadioButtonGroup(
value=starting_page,
options=list(pages.keys()),
name="Page",
sizing_mode="fixed",
button_type="success",
)
ishow = pn.bind(show, page=page)
pn.state.location.sync(page, {"value": "page"})
ACCENT_COLOR = "#0072B5"
DEFAULT_PARAMS = {
"site": "Panel Multi Page App",
"accent_base_color": ACCENT_COLOR,
"header_background": ACCENT_COLOR,
}
pn.template.FastListTemplate(
title="As Single Page App",
sidebar=[page],
main=[ishow],
**DEFAULT_PARAMS,
).servable()
async def run():
while True:
await sleep(0.1)
data = pn.state.cache["data"]
dfstream.send(pd.DataFrame(data, index=[pd.Timestamp.now()]))
pn.state.onload(run)
I haven’t found any issues while navigating between the pages and the streaming plot keeps updating in the background.
I hope this helps.