Holoviews: Django And holoviews: Widgets not responding

Created on 6 Feb 2018  Â·  17Comments  Â·  Source: holoviz/holoviews

I opened a question about this on stack-overflow. Since I got no answers, I decided to repost here since there may be other people facing the same problems.

Most helpful comment

Try changing it to:

plot_rv = renderer.get_widget(rvol, None, position='above', doc=doc).state

All 17 comments

Seems like I missed your question, would you mind trying the example using HoloViews master or have you already tried that?

I am currently using master, which was necessary to solve the issue I reported earlier.

It occurred to me that the widgets may be making POST requests back to the Django view, but I am not listening to them. I'll check that and report back soon.

I don't think that's the case. If you're embedding holoviews in django you will also have to launch a bokeh server which would be communicating via websockets. I believe @ceball recently looked into this, so it would be great to hear his thoughts on the matter.

I think @ceball was embedding bokeh server, i.e., importing it as a Python library from within the Django app, rather than launching it as a separate process. I've asked him to make his example code for that public, so hopefully he can add a pointer to it here.

Ok meanwhile I will take a look at the bokeh docs to see what they say
about embedding the server.

Em 7 de fev de 2018 19:50, "James A. Bednar" notifications@github.com
escreveu:

I think @ceball https://github.com/ceball was embedding bokeh server,
i.e., importing it as a Python library from within the Django app, rather
than launching it as a separate process. I've asked him to make his example
code for that public, so hopefully he can add a pointer to it here.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ioam/holoviews/issues/2311#issuecomment-363922681,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAIjW7g2lLwENewe0aUEedPkoLjze6Niks5tShq6gaJpZM4R66MG
.

I found this example in Bokeh repo, but is for Flask. If the widget really communicate with bokeh server through websockets integrating with Django would require a third-party app (such as channels) since Django does not have notive support to websockets.

All examples of running bokeh server in Django I've seen programmatically launch a bokeh server instance to run alongside Django so that the bokeh tornado based server handles all the comms. All Django has to do then is embed the HTML/JS components which display the plot.

Well,

here is the adaptation I came up with:

renderer = hv.renderer('bokeh').instance(mode='server')
def index2(doc):
    rvol = hv.DynamicMap(rolling_vol, kdims=['Wsize', 'Symbol']).redim.values(Symbol=symbols).redim.range(
        Wsize=(10, 60))
    plot_rv = renderer.get_widget(rvol, None, position='above').state
    doc.add_root(plot_rv)


## Code for embedding Bokeh Server
def bkapp_page(request):
    script = server_document('http://localhost:5006/bkapp')
    return render_to_response("panel/embed.html", {'script': script})

def bk_worker():
    # Can't pass num_procs > 1 in this configuration. If you need to run multiple
    # processes, see e.g. flask_gunicorn_embed.py
    server = Server({'/bkapp': index2}, allow_websocket_origin=["127.0.0.1:8000"])
    server.start()
    server.io_loop.start()

from threading import Thread
Thread(target=bk_worker).start()

I created an url pointing to bkapp_page as in the flask example and used the same template.
Although the server is started and the plot is rendered, the widget is still dead...

Try changing it to:

plot_rv = renderer.get_widget(rvol, None, position='above', doc=doc).state

Suggestion right off the top of my head so feel free to shoot it down.

Maybe we could improve the API by creating an object instance that is passed the bokeh doc on construction? Then this thing could have methods that could be called without worrying about using doc=doc all the time?

Maybe we could improve the API by creating an object instance that is passed the bokeh doc on construction

What object are you talking about here?

A new one that we define, some sort of proxy object to help with working with bokeh server, used to make the API a little easier.

I guess I can't quite envision how that would make things easier. In the example above the doc is being passed to HoloViews in exactly one place (to .get_widgets), creating a new object for that doesn't seem helpful but maybe I'm still confused about your suggestion.

In my own work on dashboards, I find myself passing doc=doc around in a number of places but I haven't done an analysis of my usage patterns. Anyway, it was just a thought I had and not a proper proposal so I'm happy to drop the suggestion.

There's definitely things we can do to make things easier, we will have to survey a wide range of use cases and see what falls out.

Adding the doc=doc to the get_widget call solved it. Thanks @philippjfr !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

claresloggett picture claresloggett  Â·  5Comments

ahuang11 picture ahuang11  Â·  5Comments

michaelaye picture michaelaye  Â·  3Comments

ericmjl picture ericmjl  Â·  3Comments

obust picture obust  Â·  5Comments