Param and panel: how to get a slider that allows a discrete list of irregularly-spaced float values?

My stackoverflow Q has gotten no traction so I decided to try my luck here…

I am using holoviz param and panel to create a dashboard displaying gridded data on a map. I have two sliders to select grid coordinates x and y. Moving the sliders displays some data for the specified gridcell.

Right now I’m using two param.Integer objects to create the sliders with the bounds set to the dimensions of the xarray dataset containing the data. When a slider moves I grab a new slice from the dataset and update the dashboard.

I’d like my sliders to display the actual longitude and latitude coordinates, not the integer indices to the xarray dataset.

I can think of several ways to do this, but haven’t gotten any of them to work.

  1. update the displayed value on the slider to show the lat or lon. This keeps the internal slider value an integer but displays the float. I can’t figure out what to update in the callback to change this value.
  2. create sliders that display lat and lon as floats. The slider’s allowed values would need to come from the list of lat and lon coordinates. The step between allowed values is not constant. So I’d need a float slider that allows, say, [74.0, 74.2, 74.5] and no other values.

Maybe (probably!) I’m just really dense but I can’t quite see how to plug together the arguments to param.Number or param.Integer to make (1) or (2) happen.

Pn.widget.DiscretSlider ?

thanks, @xavArtley. I put together what I’m trying to do using pn.widget.DiscreteSlider. Thanks for the suggestion.

I’m still confused about the “best practice” here, though: My understanding is that:

(1) param provides a modularized way to separate specifying allowed values for some arbitrary object from whatever that object does with the values themselves.
(2) Then panel provides methods to create UI widgets from the param object specifying and containing these values.

That separation seems well-considered to me, so I’m still curious if there’s a route to set this up using param.

Hi @Timothy-W-Hilton

I understand your follow question as you would like to understand how to use the Parameterized Classes api?

You can see an example below. Check out the link above for more info.

import param
import panel as pn

valid_integers = [1,2,4,7]

class MyApp(param.Parameterized):
    value = param.Selector(objects=valid_integers, label="Discrete value")

def my_model(value):
    return "Model Result: " + str(value)

app = MyApp(value=2)

widgets = pn.Param(app, widgets={"value": pn.widgets.DiscreteSlider})
imodel=pn.bind(my_model, value=app.param.value)
pn.Column(widgets, imodel).servable()