def _figure_data(self, plot, fmt='html', doc=None, **kwargs): model = plot.state if doc is None: doc = plot.document else: plot.document = doc for m in model.references(): m._document = None doc.theme = self.theme doc.add_root(model) comm_id = plot.comm.id if plot.comm else None # Bokeh raises warnings about duplicate tools and empty subplots # but at the holoviews level these are not issues logger = logging.getLogger(bokeh.core.validation.check.__file__) logger.disabled = True try: js, div, _ = notebook_content(model, comm_id) html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div) div = encode_utf8(html) doc.hold() except: logger.disabled = False raise logger.disabled = False plot.document = doc return div
def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs): """ Given a plot instance, an output format and an optional bokeh document, return the corresponding data. If as_script is True, the content will be split in an HTML and a JS component. """ model = plot.state if doc is None: doc = plot.document else: plot.document = doc for m in model.references(): m._document = None doc.theme = self.theme doc.add_root(model) # Bokeh raises warnings about duplicate tools and empty subplots # but at the holoviews level these are not issues logger = logging.getLogger(bokeh.core.validation.check.__file__) logger.disabled = True if fmt == 'png': from bokeh.io.export import get_screenshot_as_png img = get_screenshot_as_png(plot.state, None) imgByteArr = BytesIO() img.save(imgByteArr, format='PNG') data = imgByteArr.getvalue() if as_script: b64 = base64.b64encode(data).decode("utf-8") (mime_type, tag) = MIME_TYPES[fmt], HTML_TAGS[fmt] src = HTML_TAGS['base64'].format(mime_type=mime_type, b64=b64) div = tag.format(src=src, mime_type=mime_type, css='') js = '' else: try: with silence_warnings(EMPTY_LAYOUT, MISSING_RENDERERS): js, div, _ = notebook_content(model) html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div) data = encode_utf8(html) doc.hold() except: logger.disabled = False raise logger.disabled = False plot.document = doc if as_script: return div, js return data
def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs): """ Given a plot instance, an output format and an optional bokeh document, return the corresponding data. If as_script is True, the content will be split in an HTML and a JS component. """ model = plot.state if doc is None: doc = plot.document else: plot.document = doc for m in model.references(): m._document = None doc.theme = self.theme doc.add_root(model) # Bokeh raises warnings about duplicate tools and empty subplots # but at the holoviews level these are not issues logger = logging.getLogger(bokeh.core.validation.check.__file__) logger.disabled = True if fmt == 'png': from bokeh.io.export import get_screenshot_as_png img = get_screenshot_as_png(plot.state, None) imgByteArr = BytesIO() img.save(imgByteArr, format='PNG') data = imgByteArr.getvalue() if as_script: b64 = base64.b64encode(data).decode("utf-8") (mime_type, tag) = MIME_TYPES[fmt], HTML_TAGS[fmt] src = HTML_TAGS['base64'].format(mime_type=mime_type, b64=b64) div = tag.format(src=src, mime_type=mime_type, css='') js = '' else: try: js, div, _ = notebook_content(model) html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div) data = encode_utf8(html) doc.hold() except: logger.disabled = False raise logger.disabled = False plot.document = doc if as_script: return div, js return data
def _figure_data(self, plot, fmt='html', doc=None, as_script=False, **kwargs): """ Given a plot instance, an output format and an optional bokeh document, return the corresponding data. If as_script is True, the content will be split in an HTML and a JS component. """ model = plot.state if doc is None: doc = plot.document else: plot.document = doc for m in model.references(): m._document = None doc.theme = self.theme doc.add_root(model) comm_id = plot.comm.id if plot.comm else None # Bokeh raises warnings about duplicate tools and empty subplots # but at the holoviews level these are not issues logger = logging.getLogger(bokeh.core.validation.check.__file__) logger.disabled = True try: js, div, _ = notebook_content(model, comm_id) html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div) html = encode_utf8(html) doc.hold() except: logger.disabled = False raise logger.disabled = False plot.document = doc if as_script: return div, js return html
def bokeh_notebook_div(image): """" Generates an HTML div to embed in the notebook. Parameters ---------- image: InteractiveImage InteractiveImage instance with a plot Returns ------- div: str HTML string containing the bokeh plot to be displayed """ if bokeh_version > '0.12.9': js, div, _ = notebook_content(image.p, image.ref) html = NOTEBOOK_DIV.format(plot_script=js, plot_div=div) div = encode_utf8(html) # Ensure events are held until an update is triggered image.doc.hold() else: div = notebook_div(image.p, image.ref) return div