Updating Button state and Paragraph text on click

I’m running a Bokeh serve app and want to update the disabled and text properties of a Button and Div widgets when that button clicked. The problem is that also in the same callback another code that takes around 2 mins to run is executed. What im trying to do is upate the status of the two widgets before running that code but what I see is that the text and button change only after the whole code is finished.

Example:

from bokeh.models import Div, Button
from bokeh.layouts import layout
from bokeh.io import curdoc

button_download = Button(label=‘Download’, button_type=“danger”)
paragraph_server = Div(text=‘Wait for click’, width=400, height=100)

def download(event):
button_download.disabled = True
paragraph_server.text = ‘Downloading’

Time consuming code

button_download.on_click(download)
l=layout([button_download, paragraph_server])
doc = curdoc().add_root(l)

Its only a example to ilustrate the code.

Thank you in advice,

Josu Catalina.

The answer is here: The bokeh document is only updated after the callback has finished

I get this error which dont occur when directly calling the function instead of using curdoc().add_next_tick_callback(function)

2020-04-01 17:56:09,957 Exception in callback functools.partial(<bound method IOLoop._discard_future_result of <tornado.platform.asyncio.AsyncIOMainLoop object at 0x000001DABEABF7F0>>, <Task finished coro=<_needs_document_lock.._needs_document_lock_wrapper() done, defined at c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\server\session.py:51> exception=TypeError("‘NoneType’ object is not callable",)>)
Traceback (most recent call last):
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\tornado\ioloop.py”, line 743, in _run_callback
ret = callback()
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\tornado\ioloop.py”, line 767, in _discard_future_result
future.result()
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\server\session.py”, line 67, in _needs_document_lock_wrapper
result = func(self, *args, **kwargs)
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\server\session.py”, line 195, in with_document_locked
return func(*args, **kwargs)
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\document\document.py”, line 1164, in wrapper
return doc._with_self_as_curdoc(invoke)
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\document\document.py”, line 1150, in _with_self_as_curdoc
return f()
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\document\document.py”, line 1163, in invoke
return f(*args, **kwargs)
File “c:\users\catal\appdata\local\programs\python\python36\lib\site-packages\bokeh\document\document.py”, line 953, in remove_then_invoke
return callback(*args, **kwargs)
TypeError: ‘NoneType’ object is not callable

Maybe im losing something

First of all, please use formatting to properly format your code/exception blocks. It’s very hard to read them otherwise, when they’re mixed with the regular text.

Second of all, I cannot tell you what’s going on without you providing any code. If you provide the code that doesn’t work for you (ideally, stripped down to the very part that doesn’t work), I will take a look.