Skip to content

Commit

Permalink
BokehRenderer.save now includes necessary HTML assets (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens authored and philippjfr committed Jun 15, 2017
1 parent 768b83a commit fcf4417
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions holoviews/plotting/bokeh/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def __call__(self, obj, fmt=None, doc=None):
elif fmt == 'json':
return self.diff(plot), info

@bothmethod
def _save_prefix(self_or_cls, ext):
"Hook to prefix content for instance JS when saving HTML"
if ext == 'html':
return '\n'.join(self_or_cls.html_assets()).encode('utf8')
return

@bothmethod
def get_plot(self_or_cls, obj, doc=None, renderer=None):
Expand Down
8 changes: 8 additions & 0 deletions holoviews/plotting/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ def save(self_or_cls, obj, basename, fmt='auto', key={}, info={}, options=None,
if rendered is None: return
(data, info) = rendered
encoded = self_or_cls.encode(rendered)
prefix = self_or_cls._save_prefix(info['file-ext'])
if prefix:
encoded = prefix + encoded
if isinstance(basename, BytesIO):
basename.write(encoded)
basename.seek(0)
Expand All @@ -482,6 +485,11 @@ def save(self_or_cls, obj, basename, fmt='auto', key={}, info={}, options=None,
with open(filename, 'wb') as f:
f.write(encoded)

@bothmethod
def _save_prefix(self_or_cls, ext):
"Hook to prefix content for instance JS when saving HTML"
return


@bothmethod
def get_size(self_or_cls, plot):
Expand Down

0 comments on commit fcf4417

Please sign in to comment.