Is there a straightforward way to specify the type of widget that is associated with a hv.DynamicMap
or hv.HoloMap
? In some cases the widget is a slider, like the image below, and in other cases the widget is a dropdown, but it is not clear to my why one or the other is chosen.
For example is it possible to pass an argument to hv.DynamicMap
, or perhaps could I go through panel and access the pn.pane.HoloViews(dmap).widget
object?
Image created using the Minimum Example, below:
Minimum Example
Minimum Example
# =========================================
# Imports
# =========================================
import numpy as np
import pandas as pd
import holoviews as hv
from functools import partial
hv.extension("bokeh")
hv.output(widget_location='bottom')
def prep_data():
"""Generate pseudo data representing in-situ measurements on different dates"""
t = pd.date_range("2025-01-01","2025-01-07")
pts = np.random.random(size=(20,2))
data_rows = []
for t0 in t:
for p0 in pts:
x0, y0 = p0
z0 = ((x0 ** 2) + np.sin(y0)) * np.random.randn()
data_rows.append([t0,x0,y0,z0])
table = hv.Table(
data = pd.DataFrame(data_rows,columns=['DATE','XVAL','YVAL','ZVAL']),
kdims=['DATE'],
)
return table
def scatter_dmap(date,table):
"""Callback for DynamicMap to display measurements on a specific date"""
table_subset = table[table['DATE']==date]
scatter = hv.Points(
table_subset,
kdims=['XVAL','YVAL']
).opts(
size = 15,
color = 'ZVAL',
line_color = 'k',
tools=['hover'],
width=400,
height=400
)
return scatter
# =========================================
# Make the DynamicMap
# =========================================
table = prep_data()
scatter_dmap = partial(scatter_dmap,table=table)
dmap = hv.DynamicMap(scatter_dmap,kdims=['DATE'])
dmap = dmap.redim.values(**{'DATE':np.unique(table['DATE'])})
dmap