0

I'm using hvPlot and streamz to display real-time data from a Redis cache, in a Panel application. hvPlot is appending the datapoint to the chart, at one point when a limit of some kind of buffer is reached and the data will slide on his own, showing the last X datapoints.

I don't know if this feature comes from my PeriodicDataFrame or from my hvPlot plot, but I would like to explicitly (to create a user preference) set a row limit for my PeriodicDataFrame, if possible.

Here is my code:

import json
import pandas as pd
import hvplot.streamz
import holoviews as hv
from panel.widgets import IntSlider
from streamz.dataframe import PeriodicDataFrame
import redis
import panel as pn

pn.extension(sizing_mode="stretch_width")

# Connect to Redis cache
r = redis.Redis()

# Set up callback with streaming data
def sin_data(**kwargs):
    # Read the last element from the Redis list
    data = r.lindex('random_sin', -1)
    if data:
        data = json.loads(data)
        index = pd.to_datetime(data['timestamp'], unit='ms')
        return pd.DataFrame({'var_0': data['var_0'],
                           'var_1': data['var_1'],
                           'var_2': data['var_2'],
                           'var_3': data['var_3'],
                           'var_4': data['var_4'],
                           'var_5': data['var_5'],
                           'var_6': data['var_6'],
                           'var_7': data['var_7']},
                          columns=['var_' + str(x) for x in range(8)], index=[index])

df_1 = PeriodicDataFrame(sin_data, interval='100ms')

# Declare plots
line_1 = df_1.hvplot(kind='line', value_label="Sin", width=1200)

# some part about widgets
...

hv.extension('bokeh')
hv.renderer('bokeh').theme = 'caliber'
controls = pn.WidgetBox('# Commands',
                        ...
                        )

pn.template.FastListTemplate(
    site="Panel", 
    title="PoC", 
    sidebar=[*controls], 
    main=[
        "POC hvPlot, Bokeh, Panel",
        line_1,
    ]
).servable();

Thanks in advance.

  • I don't recall any buffer limit by default, but you can add an explicit limit using `.window(n=100)`; see https://streamz.readthedocs.io/en/latest/dataframes.html – James A. Bednar Mar 16 '23 at 17:13

0 Answers0