from datetime import datetime
import hvplot.pandas # pylint: disable=unused-import
import numpy as np
import pandas as pd
import panel as pn
from streamz.dataframe import DataFrame as sDataFrame
ACCENT = "red"
def _create_hvplot(data):
return data.hvplot(y="y", color=ACCENT).opts(default_tools=[])
pn.extension(sizing_mode="stretch_width")
template = pn.template.FastGridTemplate(
theme="dark",
main_max_width="",
row_height=110,
accent_base_color=ACCENT,
header_background=ACCENT,
prevent_collision=True,
save_layout=True,
)
hvplot_pane = pn.pane.HoloViews(sizing_mode="stretch_both")
df_stream = sDataFrame(example=pd.DataFrame({"y": []}, index=pd.DatetimeIndex([])))
df_window_stream = df_stream.cumsum().stream.sliding_window(50).map(pd.concat)
def update_hvplot(data):
hvplot_pane.object = _create_hvplot(data)
df_window_stream.sink(update_hvplot)
def emit():
df_stream.emit(
pd.DataFrame({"y": [np.random.randn()]}, index=pd.DatetimeIndex([datetime.utcnow()]))
)
emit()
pn.state.add_periodic_callback(emit, period=250, count=240) # Will stream for 1 mins
template.main[3:7, 0:6] = pn.Column(
pn.pane.Markdown("## BOKEH via HOLOVIEWS"), hvplot_pane, sizing_mode="stretch_both"
)
template.servable()
While running the python script above on panel 0.13.0rc5 I also got lots of errors in the console when refreshing.
$ panel serve 'script.py' --auto --show
2022-04-07 20:53:19,893 Task exception was never retrieved
future: <Task finished name='Task-9611' coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py:1100> exception=WebSocketClosedError()>
Traceback (most recent call last):
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py", line 1102, in wrapper
await fut
tornado.iostream.StreamClosedError: Stream is closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py", line 1104, in wrapper
raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
2022-04-07 20:54:23,023 - tornado.application - ERROR - Uncaught exception GET /script?theme=default (::1)
HTTPServerRequest(protocol='http', host='localhost:5006', method='GET', uri='/script?theme=default', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\web.py", line 1704, in _execute
result = await result
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\panel\io\server.py", line 245, in get
session = await self.get_session()
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\server\views\session_handler.py", line 144, in get_session
session = await self.application_context.create_session_if_needed(session_id, self.request, token)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\server\contexts.py", line 243, in create_session_if_needed
self._application.initialize_document(doc)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\panel\io\server.py", line 204, in initialize_document
super().initialize_document(doc)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\application\application.py", line 194, in initialize_document
h.modify_document(doc)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\panel\io\server.py", line 417, in modify_document
state.onload(autoreload_watcher)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\panel\io\state.py", line 428, in onload
self.curdoc.on_event('document_ready', self._schedule_on_load)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\document\document.py", line 562, in on_event
self.callbacks.on_event(event, *callbacks)
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\bokeh\document\callbacks.py", line 283, in on_event
self._event_callbacks[event].extend(callbacks)
AttributeError: 'DocumentCallbackManager' object has no attribute '_event_callbacks'
2022-04-07 20:54:45,023 Task exception was never retrieved
future: <Task finished name='Task-30070' coro=<WebSocketProtocol13.write_message.<locals>.wrapper() done, defined at c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py:1100> exception=WebSocketClosedError()>
Traceback (most recent call last):
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py", line 1102, in wrapper
await fut
tornado.iostream.StreamClosedError: Stream is closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\repos\private\awesome-panel\.venv\lib\site-packages\tornado\websocket.py", line 1104, in wrapper
raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
When running on panel 0.12.6 and 0.13.0rc5 the HoloViews plot in the streaming app https://awesome-panel.org/streaming_plots?theme=dark flashes.
https://user-images.githubusercontent.com/42288570/162275210-a2ad4433-dfc5-46fd-b585-51e3c04bb996.mp4
This might be a regression as I did not notice this back when I initially created the application.
https://user-images.githubusercontent.com/42288570/162276570-8fb06484-d773-4584-8269-66367a0ee4da.mp4
While running the python script above on panel 0.13.0rc5 I also got lots of errors in the console when refreshing.