question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Widget rendering in Jupyter but not in Bokeh App

See original GitHub issue

I wrote a small application that renders beautifully in Juypter and shows the dropdown menu with the additional but unused dimension “date”.

But when I deploy it to a bokeh app, the widget is not shown.

# Create the main plot
def create_map_figure(data):
    import geoviews as gv
    import holoviews as hv
    import geoviews.tile_sources as gts
    from holoviews import dim, opts
    from colorcet import rainbow
    gv.extension("bokeh")

    plot_width = 800
    plot_height = 400
    tile_opts = dict(height=plot_height, xaxis=None, yaxis=None, show_grid=False)
    map_tiles = gts.CartoLight.opts(style=dict(alpha=1), plot=tile_opts)

    points_ds = gv.Dataset(data[["lon", "lat", "val", "date"]])

    points = (points_ds.to(gv.Points, kdims=["lon", "lat"], vdims=["val"])
              .options(active_tools=['wheel_zoom'], tools=["hover"])
              .opts(colorbar=True, cmap=rainbow)).opts(opts.Points(color=dim('val'), size=5))

    return map_tiles * points.redim.range(change=(0, 10))


def modify_doc(doc):
    import holoviews as hv
    from bokeh.layouts import column, row
    from bokeh.models import Div

    conn = get_db_connection()
    df = get_data(conn)
    plot_map = create_map_figure(df)
    renderer = hv.renderer('bokeh').instance(mode='server')
    plot_map_rendered = renderer.app(plot_map, doc)

    doc.add_root(plot_map_rendered.state)

bokeh_app = Application(FunctionHandler(modify_doc))

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

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
philippjfrcommented, Jul 11, 2019

Here you go:

import geoviews as gv
import holoviews as hv
import numpy as np
import geoviews.tile_sources as gts
from holoviews import dim, opts
from colorcet import rainbow
gv.extension("bokeh")

plot_width = 800
plot_height = 400
tile_opts = dict(height=plot_height, xaxis=None, yaxis=None, show_grid=False)
map_tiles = gts.CartoLight.opts(style=dict(alpha=1), plot=tile_opts)

point_ds = gv.Dataset(
    (np.random.rand(100), np.random.rand(100), np.random.randint(0, 3, 100), np.random.randn(100)),
    ['lon', 'lat', 'group'], 'val')

points = point_ds.to(gv.Points, ['lon', 'lat']).opts(
    active_tools=['wheel_zoom'], tools=["hover"],
    colorbar=True, cmap=rainbow, color=dim('val'), size=5)

plot = map_tiles * points.redim.range(change=(0, 10))

server = pn.panel(plot)._get_server(
    show=True, port=PORT, websocket_origin=ALLOW_WEBSOCKET_ORIGIN,
    address=HOST, debug=True)

server.start()

How can I embed a panel app using params API in that surrounding above?

Not sure I follow, could you expand on this?

1reaction
philippjfrcommented, Jul 10, 2019

Yes, pn.panel(hv_obj)._get_server(...). I think I’ll make that method public.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh/panel won't render in-line with Jupyter Lab
I'm trying to visualize Bokeh plots and panels with a Bokeh backend in a notebook in JupyterLab. Things were running fine until I...
Read more >
Using with Jupyter — Bokeh 2.4.3 Documentation
Rendered cell output of the output_notebook call ensures that the BokehJS library loads. Otherwise, Bokeh plots will not work. If this cell's type...
Read more >
panel.io.notebook — Panel v0.14.1 - HoloViz Panel
Various utilities for loading JS dependencies and rendering plots inside the Jupyter notebook. """ from __future__ import annotations import ...
Read more >
Python data visualization with Bokeh and Jupyter Notebook
Data visualization in Python with Bokeh and Jupyter Notebook ... Luckily, Bokeh makes it pretty easy to render plots in Jupyter Notebooks!
Read more >
Deploying Bokeh Apps — HoloViews v1.15.3
We can also easily use the server_doc method to get a Bokeh Document , which does not require you to make an instance...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found