File: __init__.py

package info (click to toggle)
python-pweave 0.30.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,064 kB
  • sloc: python: 30,281; makefile: 167
file content (35 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from IPython.display import display_html, display_markdown
try:
    from bokeh.resources import CDN
    from bokeh.embed import components
except ImportError:
    pass

def dedent(text):
    return "\n".join([line.lstrip() for line in text.splitlines()])

def output_pweave():
    """
    Call this once in a Pweave document to include correct
    headers for Bokeh. Analogous to Bokeh's output_notebook
    """
    out = CDN.render_css()
    out += CDN.render_js()
    #display_markdown(out, raw=True)
    display_html(out, raw=True)

def show(plot):
    """
    Include a Bokeh figure in Pweave document. Use This
    instead of ``bokeh.plotting.show``. Provides html output.

    :param plot: ``bokeh.plotting.figure`` plot to include in output.
    """

    script, div = components(plot)
    out = script
    out+= div
    #Pandoc only works if indent is removed
    #Need to display as same output, not separate, otherwise md2hml show 2 figs
    #display_markdown(dedent(out), raw=True)
    display_html(out, raw=True)