Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for streaming data #2011

Merged
merged 20 commits into from Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/user_guide/Dashboards.rst
@@ -1,6 +1,6 @@
Creating interactive dashboards
_______________________________

.. notebook:: holoviews ../../examples/user_guide/15-Dashboards.ipynb
.. notebook:: holoviews ../../examples/user_guide/16-Dashboards.ipynb
:skip_execute: True
:offset: 1
6 changes: 6 additions & 0 deletions doc/user_guide/Streaming_Data.rst
@@ -0,0 +1,6 @@
Working with Streaming Data
___________________________

.. notebook:: holoviews ../../examples/user_guide/15-Streaming_Data.ipynb
:skip_execute: True
:offset: 1
4 changes: 4 additions & 0 deletions doc/user_guide/index.rst
Expand Up @@ -57,6 +57,9 @@ concepts in HoloViews:
* `Working with large data <Large_Data.html>`_
Leverage Datashader to interactively explore millions or billions of datapoints.

* `Working with Streaming Data <Streaming_Data.html>`_
Demonstrates how to leverage the streamz library with HoloViews to work with streaming datasets.

* `Creating interactive dashboards <Dashboards.html>`_
Use external widget libraries to build custom, interactive dashboards.

Expand Down Expand Up @@ -111,6 +114,7 @@ These guides provide detail about specific additional features in HoloViews:
Custom Interactivity <Custom_Interactivity>
Data Processing Pipelines <Data_Pipelines>
Working with large data <Large_Data>
Working with streaming data <Streaming_Data>
Creating interactive dashboards <Dashboards>
Plotting with Bokeh <Plotting_with_Bokeh>
Deploying Bokeh Apps <Deploying_Bokeh_Apps>
Expand Down
62 changes: 62 additions & 0 deletions examples/gallery/apps/bokeh/streaming_psutil.py
@@ -0,0 +1,62 @@
import datetime as dt

import psutil
import pandas as pd
import holoviews as hv

hv.extension('bokeh')

# Define functions to get memory and CPU usage
def get_mem_data():
vmem = psutil.virtual_memory()
df = pd.DataFrame(dict(free=vmem.free/vmem.total,
used=vmem.used/vmem.total),
index=[pd.Timestamp.now()])
return df*100

def get_cpu_data():
cpu_percent = psutil.cpu_percent(percpu=True)
df = pd.DataFrame(list(enumerate(cpu_percent)),
columns=['CPU', 'Utilization'])
df['time'] = pd.Timestamp.now()
return df


# Define DynamicMap callbacks returning Elements

def mem_stack(data):
data = pd.melt(data, 'index', var_name='Type', value_name='Usage')
areas = hv.Dataset(data).to(hv.Area, 'index', 'Usage')
return hv.Area.stack(areas.overlay()).relabel('Memory')

def cpu_box(data):
return hv.BoxWhisker(data, 'CPU', 'Utilization').relabel('CPU Usage')


# Set up StreamingDataFrame and add async callback

cpu_stream = hv.streams.Buffer(get_cpu_data(), 800, index=False)
mem_stream = hv.streams.Buffer(get_mem_data())

def cb():
cpu_stream.send(get_cpu_data())
mem_stream.send(get_mem_data())


# Define DynamicMaps and display plot

cpu_dmap = hv.DynamicMap(cpu_box, streams=[cpu_stream])
mem_dmap = hv.DynamicMap(mem_stack, streams=[mem_stream])

cpu_opts = {'plot': dict(width=500, height=400, color_index='CPU'),
'style': dict(box_fill_color=hv.Cycle('Category20'))}
mem_opts = dict(height=400, width=400)

plot = (cpu_dmap.redim.range(Utilization=(0, 100)).opts(**cpu_opts) +
mem_dmap.redim.range(Usage=(0, 100)).opts(plot=mem_opts))


# Render plot and attach periodic callback

doc = hv.renderer('bokeh').server_doc(plot)
doc.add_periodic_callback(cb, 0.05)