Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Holoviews app with multiple independent DynamicMap plots?

I am trying to create a grid layout (say 2x2) of plots of the DynamicMap type using holoviews. This is to be served as a Holoviews/Bokeh app.

After creating my dmaps I Lay them out using

layout = hv.Layout([dmap1, dmap2]).cols(2)

this layout generates a two plots side-by-side The problem I am facing is that by default, the widgets for each Dynamic Map get clustered to the rightof the row , with no visual association to the plots (the maps toolbars also get combined into just one).

Moreover, If I pass more than two dmaps to the layout, I get an error:

TypeError: DynamicMap does not accept AdjointLayout type, data elements have to be a ('ViewableElement', 'NdMapping', 'Layout'). 

I am using the renderer in server mode:

renderer = hv.renderer('bokeh')
renderer = renderer.instance(mode='server')

In summary, I want to have a grid of more than 2 independently controlable dynamical plots.

like image 821
fccoelho Avatar asked Sep 19 '25 11:09

fccoelho


1 Answers

There's a lot to unpack here, so let me start out answering this question:

the widgets for each Dynamic Map get clustered to the right of the row

If you want independent sets of widgets you will have to construct each set of widgets manually and compose the resulting bokeh models yourself. This example demonstrates this approach:

import numpy as np
import holoviews as hv

from bokeh.io import curdoc
from bokeh.layouts import row

renderer = hv.renderer('bokeh').instance(mode='server')

dmap1 = hv.DynamicMap(lambda x: hv.Curve(np.random.rand(10)), kdims='x').redim.range(x=(0,5))
dmap2 = hv.DynamicMap(lambda y: hv.Scatter(np.random.rand(10)), kdims='y').redim.range(x=(0,5))

widget1 = renderer.get_widget(dmap1, None, position='above').state
widget2 = renderer.get_widget(dmap2, None, position='above').state

r = row(widget1, widget2)

doc = curdoc()
doc.add_root(r)

We create two independent DynamicMaps, then use the renderer to generate separate plots and widgets and then compose them using the bokeh row layout. As you can see we can also define a position for the widgets so instead of laying them out on the right they are on top.

the maps toolbars also get combined into just one

In this recent PR a new merge_tools option was added to allow having separate toolbars in a single Layout.

Moreover, If I pass more than two dmaps to the layout, I get an error:

This is probably due to returning an adjoined object, which is not allowed inside a DynamicMap at the moment. Are you by any chance using the .hist method? If so try calling it on the DynamicMap instead of having the DynamicMap return an object with an adjoined Histogram.

like image 69
philippjfr Avatar answered Sep 22 '25 00:09

philippjfr