holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 403 forks source link

datashader bokeh server #3802

Closed anderl80 closed 5 years ago

anderl80 commented 5 years ago

I tried to integrate datashader in a Bokeh App to deploy on Cloud Foundry like here (with the help of this).

The modify_doc looks like

def modify_doc(doc):
    conn = get_db_connection()
    df = get_data(conn)
    plot_map = create_map_figure(df, doc)

    doc.add_root(plot_map)

and the create_map_figure basically like this

def create_map_figure(data, doc):
    from holoviews.operation.datashader import datashade
    import geoviews.tile_sources as gts
    import holoviews as hv
    renderer = hv.renderer('bokeh')
    shade_pd = ...
    map_tiles = gts.CartoLight.opts(style=dict(alpha=1), plot=tile_opts)
    lines = hv.Curve(...)
    routes = datashade(lines)
    plot = renderer.get_plot(map_tiles*routes, doc=doc)
    return plot

I run the app using python app.py (Tornado)

bokeh_app = Application(FunctionHandler(modify_doc))

server = Server(
        {'/': bokeh_app},
        io_loop=io_loop,
        allow_websocket_origin=ALLOW_WEBSOCKET_ORIGIN,
        **{'port': PORT, 'address': HOST}
        )
server.start()

if __name__ == '__main__':
    io_loop.add_callback(server.show, "/")
    io_loop.start()

But just can't make it work. Any help appreciated.

anderl80 commented 5 years ago

I was able to do it using:

create_map_figure returns map_tiles*routes

and replaced in modify_doc

renderer = hv.renderer('bokeh').instance(mode='server')
plot_map_rendered = renderer.get_plot(plot_map, doc)

doc.add_root(plot_map_rendered.state)