Skip to content

Commit

Permalink
Added BokehRenderer.app method to create bokeh apps in scripts and no…
Browse files Browse the repository at this point in the history
…tebooks
  • Loading branch information
philippjfr committed Apr 12, 2017
1 parent 5fd2104 commit 7a61ed2
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion holoviews/plotting/bokeh/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import param
from param.parameterized import bothmethod


from bokeh.application.handlers import FunctionHandler
from bokeh.application import Application
from bokeh.charts import Chart
from bokeh.document import Document
from bokeh.embed import notebook_div
from bokeh.io import load_notebook, curdoc
from bokeh.io import load_notebook, curdoc, show
from bokeh.models import (Row, Column, Plot, Model, ToolbarBox,
WidgetBox, Div, DataTable, Tabs)
from bokeh.plotting import Figure
Expand Down Expand Up @@ -92,6 +95,28 @@ def get_widget(self_or_cls, plot, widget_type, **kwargs):
return super(BokehRenderer, self_or_cls).get_widget(plot, widget_type, **kwargs)


@bothmethod
def app(self, plot, notebook=False):
"""
Creates a bokeh app from a HoloViews object or plot. By
default simply uses attaches plot to bokeh's curdoc and
returns the Document, if notebook option is supplied creates
an Application instance, displays it and returns it.
"""
renderer = self_or_cls.instance(mode='server')
if not notebook:
doc, _ = renderer(plot)
return doc

def modify_doc(doc):
renderer(plot, doc=doc)

handler = FunctionHandler(modify_doc)
app = Application(handler)
show(app)
return app


def server_doc(self, plot, doc=None):
"""
Get server document.
Expand Down

0 comments on commit 7a61ed2

Please sign in to comment.