question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HV to use Bokeh sources directly

See original GitHub issue

Since there is such a tight integration between Holoviews and Bokeh, is it possible to use Bokeh ColumnDataSource (and by extension AjaxDataSource) to feed the HV plots? A trivial example would be:

xs = range(-10,11)
ys = [100-x**2 for x in xs]
source = ColumnDataSource({'xs':xs, 'ys':ys})

#Bokeh
p = figure(plot_width=400, plot_height=400)
p.line('xs', 'ys', source=source)
show(p)

#Current Holoviews
curve = hv.Curve((xs, ys))
curve

#Proposed Holoviews
curve = hv.Curve(('xs', 'ys'), source=source)
curve

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ahuang11commented, Sep 3, 2018

I’m not entirely sure what CDS/AjaxDataSource is, but here’s a potential workaround?

Also, usually, the workflow is from holoviews -> bokeh (you can get back the bokeh object by doing hv.renderer('bokeh').get_plot(your_holoviews_object).state)

image

import pandas as pd
import holoviews as hv

df = pd.read_json('http://gherka.pythonanywhere.com/data')
hv.Scatter(df)
0reactions
gherkacommented, Sep 6, 2018

Thanks a lot for comments and suggestions. In the end I decided to go with pure Bokeh as exporting Holoviews’ HoloMap into a static HTML didn’t work. Rather than that, I tweaked the API to accept parameters so that the API call would return the filtered data:

initial_state = r'http://gherka.pythonanywhere.com/data/HB=NHS Tree&Sex=Male&Measure=Big Count'
source = AjaxDataSource(data_url=initial_state, method='GET')

p = figure(plot_width=800, plot_height=300)

p.line('Year', 'Value', source=source)
p.grid.visible = False
p.title.align='center'

select_hb = Select(title="Select Health Board:", value="NHS Tree",
                options=["NHS Tree", "NHS Rock", "NHS Train"])

select_measure = Select(title="Select measure:", value="Big Count",
                       options=["Big Count", "Small Rate"])

callback_hb = CustomJS(args=dict(source=source), code="""
    if (typeof measure === 'undefined'){
    measure = 'Big Count'; //default value
    };

    hb = cb_obj.value;
    var new_url = `http://gherka.pythonanywhere.com/data/HB=${hb}&Sex=Male&Measure=${measure}`;

    fetch(new_url).then(function(response) { return response.json(); })
    .then(function(result) {source.data = result;})
    
    source.change.emit();
""")

callback_measure = CustomJS(args=dict(source=source), code="""
    if (typeof hb === "undefined"){
    hb = 'NHS Tree'; //default value
    };

    measure = cb_obj.value;
    var new_url = `http://gherka.pythonanywhere.com/data/HB=${hb}&Sex=Male&Measure=${measure}`;

    fetch(new_url).then(function(response) { return response.json(); })
    .then(function(result) {source.data = result;})

    source.change.emit();
""")

select_measure.js_on_change('value', callback_measure)
select_hb.js_on_change('value', callback_hb)

layout = column(row(select_hb, select_measure),p)
show(layout)

ajax filters

Read more comments on GitHub >

github_iconTop Results From Across the Web

HV to use Bokeh sources directly #2978 - holoviz/holoviews
The advantage (to my limited understanding) is that you can have a static HTML showing the visualisation and the data for it delivered...
Read more >
Providing data — Bokeh 2.4.3 Documentation
This section describes the various ways to provide data to Bokeh, from passing data values directly to creating a ColumnDataSource (CDS) and filtering...
Read more >
Plotting with Bokeh — HoloViews v1.15.3
Plotting with Bokeh#. import numpy as np import pandas as pd import holoviews as hv from holoviews import dim, opts hv.extension('bokeh').
Read more >
Python Data Visualization With Bokeh - YouTube
In this video we will get started with data visualization in Python by creating a top horsepower chart using the Bokeh ...
Read more >
Visualizing Data with Bokeh and Pandas
This tutorial assumes that you have a basic knowledge of the Python language and its associated data structures, particularly lists. If you work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found