import panel as pn import asyncio pn.extension() button = pn.widgets.Button(name='Click me!') text = pn.widgets.StaticText() async def run_async(event): text.value = f'Running {event.new}' await asyncio.sleep(2) text.value = f'Finished {event.new}' button.on_click(run_async) pn.Row(button, text) import numpy as np from bokeh.plotting import figure from bokeh.models import ColumnDataSource button = pn.widgets.Button(name='Click me!') p = figure(width=500, height=300) cds = ColumnDataSource(data={'x': [0], 'y': [0]}) p.line(x='x', y='y', source=cds) pane = pn.pane.Bokeh(p) @pn.io.with_lock async def stream(event): await asyncio.sleep(1) x, y = cds.data['x'][-1], cds.data['y'][-1] cds.stream({'x': list(range(x+1, x+6)), 'y': y+np.random.randn(5).cumsum()}) pane.param.trigger('object') # Equivalent to `.on_click` but shown button.param.watch(stream, 'clicks') pn.Row(button, pane) import time import threading c = threading.Condition() button = pn.widgets.Button(name='Click to launch') text = pn.widgets.StaticText() queue = [] def callback(): global queue while True: c.acquire() for i, q in enumerate(queue): text.value = f'Processing item {i+1} of {len(queue)} items in queue.' time.sleep(2) queue.clear() text.value = "Queue empty" c.release() time.sleep(1) thread = threading.Thread(target=callback) thread.start() def on_click(event): queue.append(event) button.on_click(on_click) pn.Row(button, text).servable()