Disable button responsively

Here, I use a bit of Javascript to disable the button instead of just a Python callback to make it more responsive to being disabled (and prevent double submissions).

import param

import time
import panel as pn
pn.extension()

def python_callback(event):
    select.disabled = True  # needed to tell python side it's disabled
    time.sleep(1)
    select.disabled = False

select = pn.widgets.Select(options=['Just Testing'])
button = pn.widgets.Button(name='Process!')

button.js_on_click(args={"target": select}, code="target.disabled = true;")
select.jslink(button, code={"disabled": "target.disabled = source.disabled;"}, bidirectional=True)
button.param.watch(python_callback, "clicks")

pn.Column(select, button)
2 Likes