Ejemplo n.º 1
0
 def load_nb(cls, inline=True):
     """
     Loads the bokeh notebook resources.
     """
     from bokeh.io.notebook import curstate
     load_notebook(hide_banner=True, resources=INLINE if inline else CDN)
     curstate().output_notebook()
Ejemplo n.º 2
0
def _fig_repr_html(self):
    """ Figure can display itself """
    from bokeh.io.notebook import load_notebook
    from bokeh.embed.notebook import notebook_content

    load_notebook(hide_banner=True)
    (script, div, cell_doc) = notebook_content(self)
    return f'{div}<script>{script}</script>'
Ejemplo n.º 3
0
 def load_nb(cls, inline=True):
     """
     Loads the bokeh notebook resources.
     """
     LOAD_MIME_TYPE = bokeh.io.notebook.LOAD_MIME_TYPE
     bokeh.io.notebook.LOAD_MIME_TYPE = MIME_TYPES['jlab-hv-load']
     load_notebook(hide_banner=True, resources=INLINE if inline else CDN)
     bokeh.io.notebook.LOAD_MIME_TYPE = LOAD_MIME_TYPE
     bokeh.io.notebook.curstate().output_notebook()
Ejemplo n.º 4
0
 def load_nb(cls, inline=True):
     """
     Loads the bokeh notebook resources.
     """
     LOAD_MIME_TYPE = bokeh.io.notebook.LOAD_MIME_TYPE
     bokeh.io.notebook.LOAD_MIME_TYPE = MIME_TYPES['jlab-hv-load']
     load_notebook(hide_banner=True, resources=INLINE if inline else CDN)
     bokeh.io.notebook.LOAD_MIME_TYPE = LOAD_MIME_TYPE
     bokeh.io.notebook.curstate().output_notebook()
Ejemplo n.º 5
0
 def load_nb(cls, inline=True):
     """
     Loads the bokeh notebook resources.
     """
     kwargs = {'notebook_type': 'jupyter'} if '0.12.9' >= bokeh_version > '0.12.5' else {}
     load_notebook(hide_banner=True, resources=INLINE if inline else CDN, **kwargs)
     if bokeh_version <= '0.12.9':
         from bokeh.io import _state
         _state.output_notebook()
     else:
         from bokeh.io.notebook import curstate
         curstate().output_notebook()
Ejemplo n.º 6
0
    def _repr_html_(self) -> str:
        """
        Display itself inside a notebook
        """
        # Speical case inside Google Colab
        if "google.colab" in sys.modules:
            load_notebook(hide_banner=True)
            script, div, _ = notebook_content(self.to_render)
            return f"{div}<script>{script}</script>"

        # Windows forbids us open the file twice as the result bokeh cannot
        # write to the opened temporary file.
        with NamedTemporaryFile(suffix=".html", delete=False) as tmpf:
            pass

        save(
            self.to_render,
            filename=tmpf.name,
            resources=CDN,
            template=INLINE_TEMPLATE,
            title="DataPrep.EDA Report",
        )
        with open(tmpf.name, "r") as f:
            output_html = f.read()

        # Delete the temporary file
        Path(tmpf.name).unlink()

        # Fix the bokeh: bokeh wrongly call the "waiting for bokeh to load" function
        # inside "Bokeh.safely", which causes Bokeh not found because
        # Bokeh is even not loaded!
        patched_html = output_html.replace(
            "Bokeh.safely",
            "var __dataprep_bokeh_fix = (f) => document.Bokeh === undefined ? setTimeout(f, 1000) : f(); __dataprep_bokeh_fix",  # pylint: disable=line-too-long
        )
        # embed into report template created by us here
        return patched_html
Ejemplo n.º 7
0
def _report_repr_html_(self):
    from bokeh.io.notebook import load_notebook
    from bokeh.embed.notebook import notebook_content
    load_notebook(hide_banner=True)
    script, div, _ = notebook_content(self.to_render)
    return f'{div}<script>{script}</script>'