Cancellable Button implementation

I have a custom button implementation that changes states in accordance with the on_click callback state.


  • initial - user-defined UI
  • Processing - on_click callback is running
  • Finished - on_click finished successfully -> changes to initial after 1 second with add_periodic_callback
  • Error - on_click failed running

I want to add the following functionality:

  • run on_click in a thread
  • while on_click running use a new Cancel state
  • when the user clicks Cancel -> stop the running on_click

Can this be implemented with Panel directly without Threading or asyncio?

Using Threading or asyncio io intervenes with add_periodic_callback and throws error