Plotting streamz + pipe example in a browser not working

In the first approach if you add the .servable and wrap the streaming of the df with the pn.state.onload it works.

strin

import streamz
import holoviews as hv
from holoviews.streams import Buffer, Pipe
import pandas as pd
import numpy as np
hv.extension('bokeh')
import panel as pn

point_source = streamz.Stream()
pipe = Pipe(data=pd.DataFrame({'x': [], 'y': [], 'count': []}))
point_source.sliding_window(20).map(pd.concat).sink(pipe.send) # Connect streamz to the Pipe
scatter_dmap = hv.DynamicMap(hv.Scatter, streams=[pipe])

plot = scatter_dmap.opts(bgcolor='black', color='count', ylim=(-4, 4), show_legend=False)

def update_stream():
    for i in range(100):
        df = pd.DataFrame({'x': np.random.rand(100), 'y': np.random.randn(100), 'count': i},
                        columns=['x', 'y', 'count'])
        point_source.emit(df)


pn.state.onload(update_stream)
pn.panel(plot).servable()
3 Likes