How to embed a Bokeh figure in a Dash app

Viewed 678

I would like to embed a Bokeh figure inside a Dash app, but I can't figure out how to render the Bokeh JSON in Dash.

The simplest solution would be to use Bokeh or Dash on its own. All our other apps at work use Dash (so Bokeh alone is undesirable), however, Dash/Plotly cannot generate the required figure (a raster image overlaid on a tiled map).

There is an old post on the Plotly community forum asking the same question, and the proposed solution was to use the dash-alternative-viz package to embed the Bokeh figure. Unfortunately, the package doesn't render Bokeh plots, even when copying the example usage.py script. This has been raised as an issue on the repo, but the developers have yet to respond.

Bokeh can supply JSON data that BokehJS can use to render a standalone figure (bokeh.embed.json_item()), and the docs give an example of how to serve a Bokeh figure to a Flask app:

@app.route('/plot')
def plot():
    p = make_plot('petal_width', 'petal_length')
    return json.dumps(json_item(p, "myplot"))

How can I do something similar in Dash?

1 Answers
Related