Jslink ValueError for DiscreteSlider and DatetimeInput

import panel as pn

ds1 = pn.widgets.DiscreteSlider(options=['2022-02-10','2022-02-11','2022-02-12'])
ds2 = pn.widgets.DatetimeInput()

ds1.jslink(ds2, value='value')

results in

ValueError: Cannot jslink ‘value’ parameter on DiscreteSlider object to ‘value’ parameter on DatetimeInput. It requires a live Python kernel to have an effect.

I am trying to link a DiscreteSlider with Datetime values bidirectionally with the DatetimeInput. It works with link but I feel it could be done at a lower level.


Instead of jslink may be try link like this:

import panel as pn

import datetime as dt

datetime_picker = pn.widgets.DatetimePicker(name='Datetime Picker', value=dt.datetime(2021, 3, 2, 12, 10))

ds2 = pn.widgets.DatetimeInput()

datetime_picker.link(ds2, value='value',bidirectional=True) 

pn.Row(datetime_picker,ds2,height = 500)

Kind regards

There is no DatetimeSlider so I had to use DiscreteSlider. Here is my solution

import pandas as pd
import panel as pn


time_array = [(sdate + pd.to_timedelta(f'{i*15}T')).strftime('%Y-%m-%d %H:%M') for i in range(1000)]
date_slider = pn.widgets.DiscretePlayer(
    name='Date Slider', options=time_array)
date_time_input = pn.widgets.DatetimeInput(
    name='Datetime Input', value=pd.to_datetime(date_slider.value))

def sync_slider(target, event):
    target.value = event.new.strftime('%Y-%m-%d %H:%M')
def sync_dt_input(target, event):
    target.value = pd.to_datetime(event.new)

_ = date_time_input.link(date_slider, callbacks={'value': sync_slider})
_ = date_slider.link(date_time_input, callbacks={'value': sync_dt_input})

1 Like