On this page

Streaming Indicator#

Download this notebook from GitHub (right-click to download).


import numpy as np
import pandas as pd
import panel as pn

pn.extension(sizing_mode='stretch_width')

This example demonstrates the powerful streaming capabilities of the Trend indicator.

layout = pn.layout.FlexBox(*(
    pn.indicators.Trend(
        data={'x': list(range(10)), 'y': np.random.randn(10).cumsum()},
        width=150,
        height=100,
        plot_type=pn.indicators.Trend.param.plot_type.objects[i%4]
    ) for i in range(32)
))

def stream():
    for trend in layout:
        trend.stream({'x': [trend.data['x'][-1]+1], 'y': [trend.data['y'][-1]+np.random.randn()]}, rollover=20)

cb = pn.state.add_periodic_callback(stream, 500)

pn.Card(layout)

App#

Lets wrap it into nice template that can be served via panel serve streaming_trend.ipynb

controls = pn.Row(*pn.Param(cb.param, parameters=['period', 'running'], show_name=False, width=300))
controls[1].align='end'

pn.template.FastListTemplate(
    site="Panel", 
    title="Streaming Trend", 
    main=[
        "This example demonstrates the **powerful streaming capabilities** of Panel and the `Trend` indicator.",
        controls,
        layout,
    ]
).servable();
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).