[bokeh] FunctionHandler callback check type error on doc

Hi,

This line:

  app = Application(FunctionHandler(mod_doc(doc)))

is actually passing the result of *calling* mod_doc (which is a Document) to FunctionHandler. You probably want:

  app = Application(FunctionHandler(mod_doc))

Thanks,

Bryan

···

On Aug 10, 2017, at 10:16, rick <[email protected]> wrote:

Can anyone point out the reason I'm getting the type error from the FunctionHandler callback check?
Origin:
_check_callback(func, ('doc',))
Error:
  File "C:\Anaconda3\lib\inspect.py", line 2156, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: <bokeh.document.Document object at 0x0000014E07296860> is not a callable object
Source:
from tornado.ioloop import IOLoop
from bokeh.document import Document
from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.server.server import Server

def mod_doc(doc):
    from bokeh.layouts import widgetbox, layout
    from bokeh.models.widgets import Button, Div
  
    #setup widgets
    div1 = Div(text="""<b>text1<b>""")
    div2 = Div(text="""<i>text2<i>""")
    but1 = Button(label='super foo', button_type='success')
    
    #callback and tie
    def click():
        print('click callback')
    but1.on_click(click)
    
    #setup layouts and update doc
    controls = widgetbox(div1,div2,but1, width=400)
    worksheet = layout([[controls]])
    doc.add_root(worksheet)
    doc.title = 'test'
    return doc
     
def main():
    #init doc and server
    io_loop = IOLoop.current()
    doc = Document()
    app = Application(FunctionHandler(mod_doc(doc)))
    server = Server({'/test': app}, io_loop=io_loop, port=0)
    server.start()
    io_loop.add_callback(server.show,'/test')
    io_loop.start()

if __name__ == '__main__':
    print('direct script access')
    main()
else:
    print('access via import')

The source follows same method as the embed standalone examples and works as such, but stops working when I roll everything up into main(). I'm passing the doc and creating the necessary objects but still getting the callable error.. so I'm stumped at the moment.

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/fa8ccc5d-9319-4222-8ea7-3aa1af828191%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.