Hello Community,
I’m creating a panel sever and trying to show a real-time data using tabulator with certain update period for data. When, I keep the period high e.g.1000 ms or higher, I don’t have problem showing the real-time data updates.
But, when I change the period very small for example 20 ms for sometime and then again change it to for example 10000 ms, then the print statement in my code starts updating the code in 10000 ms, but on the server it takes a lot of time to get the update.
It somehow works as, I have stopped passing the data, but it has accumulated data and it keeps showing them even after I set my period to higher value e.g 10000 ms.
Can someone please help me here, what is the reason behind this behavior and how can I make sure that I always show only the latest data on server.
following is my code:
import numpy as np
import pandas as pd
import panel as pn
from functools import partial
from icecream import ic
pn.extension('tabulator', template='fast', sizing_mode="stretch_width")
df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD')).cumsum()
rollover = pn.widgets.IntInput(name='Rollover', value=15)
follow = pn.widgets.Checkbox(name='Follow', value=True, align='end')
tabulator = pn.widgets.Tabulator(df, height=450)
def color_negative_red(val):
"""
Takes a scalar and returns a string with
the css property `'color: red'` for negative
strings, black otherwise.
"""
color = 'red' if val < 0 else 'green'
return 'color: %s' % color
tabulator.style.map(color_negative_red)
def stream():
ic()
data = df.iloc[-1] + np.random.randn(4)
tabulator.stream(data, rollover=rollover.value, follow=follow.value)
cb = pn.state.add_periodic_callback(stream, 200)
pn.Column(
pn.Row(cb.param.period, rollover, follow, width=400),
tabulator
).servable()