-
Notifications
You must be signed in to change notification settings - Fork 7
Add support for custom widget layouts #66
base: master
Are you sure you want to change the base?
Changes from 1 commit
73cfa64
49c9874
f0f188e
ca9adc1
899ea3a
65d3bda
a439f2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import sys | ||
import inspect | ||
import base64 | ||
from io import BytesIO | ||
|
||
import bokeh | ||
from bokeh.models import Model, CustomJS, LayoutDOM | ||
from bokeh.models import Model, CustomJS, LayoutDOM, Div | ||
|
||
try: | ||
from IPython.display import publish_display_data | ||
|
@@ -102,7 +104,7 @@ def patch_widgets(plot, doc, plot_id, comm): | |
|
||
def process_plot(plot, doc, plot_id, comm): | ||
""" | ||
Converts all acceptable plot and widget objects into displaybel | ||
Converts all acceptable plot and widget objects into displayable | ||
bokeh models. Patches any HoloViews plots or parambokeh Widgets | ||
with the top-level comms and plot id. | ||
""" | ||
|
@@ -118,7 +120,15 @@ def process_plot(plot, doc, plot_id, comm): | |
from holoviews import renderer | ||
renderer = renderer('bokeh').instance(mode='server' if comm is None else 'default') | ||
plot = renderer.get_plot(plot, doc=doc) | ||
|
||
elif plot.__class__.__name__ == 'Figure' and hasattr(plot, '_cachedRenderer'): | ||
bytes_io = BytesIO() | ||
plot.canvas.print_figure(bytes_io) | ||
data = bytes_io.getvalue() | ||
b64 = base64.b64encode(data).decode("utf-8") | ||
src = "data:image/png;base64,{b64}".format(b64=b64) | ||
html = "<img src='{src}'></img>".format(src=src) | ||
width, height = plot.canvas.get_width_height() | ||
return Div(text=html, width=width, height=height) | ||
if not hasattr(plot, '_update_callbacks'): | ||
raise ValueError('Can only render bokeh models or HoloViews objects.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Presumably this error message is out of date. Maybe "Not one of the currently supported displayable objects (Bokeh models, HoloViews objects, or Matplotlib figures)."? Would it be possible to have a fallback that allows any object with a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure.
Definitely not, those work using ipywidgets. |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this elif should have a comment above it saying "Matplotlib figure", as that's not at all obvious from what's being tested.