# Dynamic Map over a datashade

**URL:** <https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581>\
**Category:** HoloViews\
**Tags:** bokeh, datashader, holoviews\
**Created:** [April 28, 2020, 11:19am UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581 "2020-04-28T11:19:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josucatalina](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@Josucatalina](https://discourse.holoviz.org/u/Josucatalina)\
**Post date:** [April 28, 2020, 11:19am UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/1 "2020-04-28T11:19:23Z")

</div>

Hello,

Im using holoviews in a Bokeh serve to plot a big database, the thing is that the user can filter or even change the database for different variables and plot according to that filter. I’ve done this via DynamicMap

Example code:

```auto
    import holoviews as hv
    ...

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

    hover = HoverTool(tooltips=[('index', '$index'), ('datetime', '@Date{%Y-%m-%d:%H:%M:%S}'), 
               ('Valor', '@Value{0.00}')],
               formatters={'@Date': 'datetime'},
               mode='mouse')
    pipe = Pipe(data=np.array([[], [], 'Var']))
    dmap = hv.DynamicMap(timeseries, streams=[pipe])
    hvplot = renderer.get_plot(dmap, curdoc())
    ....
    def timeseries(data):

          return hv.Curve(dict(Date=data[0], Value=data[1]), 'Date', (('Value', data[2]))).opts(width=1200, 
                   height=600, tools=['xwheel_zoom', 'pan'], active_tools=['xwheel_zoom', 'pan'], 
                    default_tools= ['reset', 'save', hover])

```

This works perfectly as expected when pipe.send(…) the curve changes as expected (also whit hv.scatter). The problem is that the interactivity is reduced when a lot of points are plotted over 1 million. So what I am wanting to do is change the following (returning a datashade):

```auto
    def timeseries(data):

          return datashade(hv.Curve(dict(Date=data[0], Value=data[1]), 'Date', (('Value', 
                     data[2]))).opts(width=1200, height=600, tools=['xwheel_zoom', 'pan'], active_tools= 
                     ['xwheel_zoom', 'pan'], default_tools= ['reset', 'save', hover]))

```

But I get the following error:

Exception: Nesting a DynamicMap inside a DynamicMap is not supported. Ensure that the DynamicMap callback returns an Element or (Nd)Overlay. If you have applied an operation ensure it is not dynamic by setting dynamic=False.

I would like a workaround or alternative to this, HoloMap i think wouldnt work because the user can change and filter the whole database whit continuous values.

Setting dynamic to False is not a solution as user can zoom in the data

Thank You in advice.

Josu Catalina

---

<div class="post-metadata">

**Author:** ![philippjfr](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/philippjfr/32/7_2.png) [@philippjfr](https://discourse.holoviz.org/u/philippjfr)\
**Post date:** [April 28, 2020, 11:29am UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/2 "2020-04-28T11:29:09Z")

</div>

It’s pretty simple, datashade should be applied to the `DynamicMap` not inside the `DynamicMap`. Basically you should generally try to minimize the computation in a single callback and instead chain operations either by using an actual HoloViews `Operation` or by using `.apply`. In this case you construct your `DynamicMap` and then simply call `datashade` on it:

```auto
def timeseries(data):
    return hv.Curve(dict(Date=data[0], Value=data[1]), 'Date', (('Value', data[2])))

dmap = hv.DynamicMap(timeseries, streams=[pipe])
datashade(dmap).opts(
    width=1200, height=600, tools=['xwheel_zoom', 'pan'],
    active_tools=['xwheel_zoom', 'pan'], default_tools= ['reset', 'save', hover]
)

```

For more background I’d recommend reading the [Transforming Elements](http://holoviews.org/user_guide/Transforming_Elements.html) and [Data Pipelines](http://holoviews.org/user_guide/Data_Pipelines.html) user guides.

---

<div class="post-metadata">

**Author:** ![Josucatalina](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@Josucatalina](https://discourse.holoviz.org/u/Josucatalina)\
**Post date:** [April 28, 2020, 11:56am UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/3 "2020-04-28T11:56:49Z")

</div>

Thank You that solved the problem and now is much more interactive! also thanks for the fast response!.

But i am facing two different problems now sorry… I think thats because I started all this project only with bokeh library.

1.The Custom `HoverTool` seems not working not showing any data (worked without `datashader` on top)

 ![image](https://discourse.holoviz.org/uploads/default/original/1X/1b09b2d20e501a9a80674a53ee1609b7d56b092a.png)  
In the other side when I add the default ‘hover’` (tools=['hover])` to the tools I actually see the values but the Date appears as a number. I dont know how to apply formatters to the default hover tool or how to make the custom hover work in top of datashader object.  
 ![image](https://discourse.holoviz.org/uploads/default/original/1X/dc30a71b3cc41d334d894e5add1e55d537bd8be7.png)

1. Previously i adjust the range in this way:

```auto
        hvplot.state.y_range.start = min_plt - 2
        hvplot.state.y_range.end = max_plt + 2
        hvplot.state.y_range.bounds = (min_plt - 20, max_plt + 20)

```

The same using `DateTime` for x axis.

This worked fine without datashader, before when only getting `hv.Curve` from `DynamicMap` but now error messages appear. Should I use redim over datahsade object??

1. This migth be a bug but if I use first the `ywheel_zoom` tool before the other `xwheel_zoom` or `wheel_zoom` tools an error occurs. I will try to ilustrate it with some

.gif

 ![Screentogif1](https://discourse.holoviz.org/uploads/default/original/1X/54f25056ed5fcc41a6d6d6018de955cfae6052b4.gif)

```auto
future: <Future finished exception=UFuncTypeError(<ufunc 'true_divide'>, (dtype('<M8[ns]'), dtype('float64')))>
Traceback (most recent call last):
  File "c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\tornado\gen.py", line 191, in wrapper
    result = func(*args, **kwargs)
  File "c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\holoviews\plotting\bokeh\callbacks.py", line 418, in process_on_change
    self.on_msg(msg)
  File "c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\holoviews\plotting\bokeh\callbacks.py", line 141, in on_msg
    processed_msg = self._process_msg(filtered_msg)
  File "c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\holoviews\plotting\bokeh\callbacks.py", line 815, in _process_msg
    x0 = convert_timestamp(x0)
  File "c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\holoviews\plotting\bokeh\util.py", line 98, in convert_timestamp
    datetime = dt.datetime.utcfromtimestamp(timestamp/1000.)
numpy.core._exceptions.UFuncTypeError: ufunc 'true_divide' cannot use operands with types dtype('<M8[ns]') and dtype('float64')

```

But if I restart the server and use the `xwheel_zoom` first works perfectly:

 ![Screentogif2](https://discourse.holoviz.org/uploads/default/original/1X/99ec2c8bb642aca8daa3c91a764f537197c387ec.gif)

Sorry for bothering that much.

Josu Catalina

---

<div class="post-metadata">

**Author:** ![Josucatalina](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@Josucatalina](https://discourse.holoviz.org/u/Josucatalina)\
**Post date:** [April 30, 2020, 2:59pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/4 "2020-04-30T14:59:15Z")

</div>

Any solution @philippjfr ?

---

<div class="post-metadata">

**Author:** ![poplarshift](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/poplarshift/32/210_2.png) [@poplarshift](https://discourse.holoviz.org/u/poplarshift)\
**Post date:** [April 30, 2020, 3:12pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/5 "2020-04-30T15:12:31Z")

</div>

datashade returns an image which loses some of the information.

---

<div class="post-metadata">

**Author:** ![philippjfr](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/philippjfr/32/7_2.png) [@philippjfr](https://discourse.holoviz.org/u/philippjfr)\
**Post date:** [April 30, 2020, 5:28pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/6 "2020-04-30T17:28:19Z")

</div>

Right, you will want to use `rasterize` not datashade.

---

<div class="post-metadata">

**Author:** ![Josucatalina](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@Josucatalina](https://discourse.holoviz.org/u/Josucatalina)\
**Post date:** [April 30, 2020, 7:31pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/7 "2020-04-30T19:31:28Z")

</div>

Okay thanks and the 3rd problem I think its a bug or something.

---

<div class="post-metadata">

**Author:** ![philippjfr](https://discourse.holoviz.org/user_avatar/discourse.holoviz.org/philippjfr/32/7_2.png) [@philippjfr](https://discourse.holoviz.org/u/philippjfr)\
**Post date:** [April 30, 2020, 7:44pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/8 "2020-04-30T19:44:49Z")

</div>

Right, probably an error. Don’t think we anticipated usage of the `{x/y}wheel_zoom` tools. An issue would be appreciated.

---

<div class="post-metadata">

**Author:** ![Josucatalina](https://discourse.holoviz.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@Josucatalina](https://discourse.holoviz.org/u/Josucatalina)\
**Post date:** [May 2, 2020, 12:41pm UTC](https://discourse.holoviz.org/t/dynamic-map-over-a-datashade/581/9 "2020-05-02T12:41:45Z")

</div>

Issue appointed in GitHub

> <https://github.com/holoviz/holoviews/issues/4405>
>
> Using first ywheel\_zoom before xwheel\_zoom or wheel\_zoom tools in datashaded DynamicMap in Bokeh server ends in error. If any of the...

Also which could be the alternative to programatically fix the range of plots like it would be in bokeh

```auto
        hvplot.state.y_range.start = min_plt - 2
        hvplot.state.y_range.end = max_plt + 2
        hvplot.state.y_range.bounds = (min_plt - 20, max_plt + 20)

```

This does not work

Thank You.

Josu Catalina.
