Ejemplo n.º 1
0
    def show(self, app_path, browser=None, new='tab'):
        ''' Opens an app in a browser window or tab.

            Useful for testing server applications on your local desktop but
            should not call when running bokeh-server on an actual server.

        Args:
            app_path (str) : the app path to open
                The part of the URL after the hostname:port, with leading slash.

            browser (str, optional) : browser to show with (default: None)
                For systems that support it, the **browser** argument allows
                specifying which browser to display in, e.g. "safari", "firefox",
                "opera", "windows-default" (see the ``webbrowser`` module
                documentation in the standard lib for more details).

            new (str, optional) : window or tab (default: "tab")
                If ``new`` is 'tab', then opens a new tab.
                If ``new`` is 'window', then opens a new window.

        Returns:
            None
        '''
        if not app_path.startswith("/"):
            raise ValueError("app_path must start with a /")
        from bokeh.browserlib import view
        url = "http://localhost:%d%s" % (self.port, app_path)
        view(url, browser=browser, new=new)
Ejemplo n.º 2
0
    def show(self, app_path, browser=None, new='tab'):
        ''' Opens an app in a browser window or tab.

            Useful for testing server applications on your local desktop but
            should not call when running bokeh-server on an actual server.

        Args:
            app_path (str) : the app path to open
                The part of the URL after the hostname:port, with leading slash.

            browser (str, optional) : browser to show with (default: None)
                For systems that support it, the **browser** argument allows
                specifying which browser to display in, e.g. "safari", "firefox",
                "opera", "windows-default" (see the ``webbrowser`` module
                documentation in the standard lib for more details).

            new (str, optional) : window or tab (default: "tab")
                If ``new`` is 'tab', then opens a new tab.
                If ``new`` is 'window', then opens a new window.

        Returns:
            None
        '''
        if not app_path.startswith("/"):
            raise ValueError("app_path must start with a /")
        from bokeh.browserlib import view
        url = "http://localhost:%d%s" % (self.port, app_path)
        view(url, browser=browser, new=new)
Ejemplo n.º 3
0
    line_source = ColumnDataSource(dict(
        x=data.dist,
        y=data.alt,
    ))

    line = Line(x='x', y='y', line_color="black", line_width=1)
    plot.add_glyph(line_source, line)

    plot.x_range = DataRange1d(sources=[line_source.columns("x")])
    plot.y_range = DataRange1d(sources=[line_source.columns("y")])

    return plot


data = prep_data(obiszow_mtb_xcm)

trail = trail_map(data)
altitude = altitude_profile(data)

layout = VBox(children=[altitude, trail])

doc = Document()
doc.add(layout)

if __name__ == "__main__":
    filename = "trail.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Trail map and altitude profile"))
    print("Wrote %s" % filename)
    view(filename)
Ejemplo n.º 4
0
from bokeh.models import WheelZoomTool, ResizeTool, PanTool, BoxZoomTool
from bokeh.models import WMTSTileSource

output_file("tile_source_example.html", title="Tile Source Example")

# set to roughly full extent of web mercator projection
x_range = Range1d(start=-20000000, end=20000000)
y_range = Range1d(start=-20000000, end=20000000)

# create tile source from templated url
tile_options = {}
tile_options['url'] = 'http://c.tile.openstreetmap.org/{z}/{x}/{y}.png'
tile_source = WMTSTileSource(**tile_options)

# instantiate plot and add tile source
p = Plot(x_range=x_range, y_range=y_range, plot_height=800, plot_width=800)
p.add_tools(ResizeTool(), WheelZoomTool(), PanTool(), BoxZoomTool())

tile_renderer_options = {}
p.add_tile(tile_source, **tile_renderer_options)

doc = Document()
doc.add(p)

if __name__ == "__main__":
    filename = "tile_source.html"
    with open(filename, "w") as f:
        f.write(file_html(doc, INLINE, "Tile Source Example"))
    print("Wrote %s" % filename)
    view(filename)
Ejemplo n.º 5
0
    xaxis = LinearAxis()
    plot.add_layout(xaxis, 'below')

    yaxis = LinearAxis()
    plot.add_layout(yaxis, 'left')

    plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

    plot.add_tools(PanTool(), WheelZoomTool())

    document.add(plot)
    session.store_document(document)

make_plot('annular_wedge', AnnularWedge(x="x", y="y", inner_radius=0.2, outer_radius=0.5, start_angle=0.8, end_angle=3.8))
make_plot('annulus', Annulus(x="x", y="y", inner_radius=0.2, outer_radius=0.5))
make_plot('arc', Arc(x="x", y="y", radius=0.4, start_angle=0.8, end_angle=3.8))
make_plot('circle', Circle(x="x", y="y", radius=1))
make_plot('oval', Oval(x="x", y="y", width=0.5, height=0.8, angle=-0.6))
make_plot('ray', Ray(x="x", y="y", length=25, angle=0.6))
make_plot('rect', Rect(x="x", y="y", width=0.5, height=0.8, angle=-0.6))
make_plot('text', Text(x="x", y="y", text={"value":"foo"}, angle=0.6))
make_plot('wedge', Wedge(x="x", y="y", radius=0.5, start_angle=0.9, end_angle=3.2))

link = session.object_link(document.context)
print ("please visit %s to see plots" % link)
view (link)


Ejemplo n.º 6
0
    {{ plot_script }}
    </body>
</html>
''')

resources = INLINE

js_resources = JS_RESOURCES.render(
    js_raw=resources.js_raw,
    js_files=resources.js_files
)

css_resources = CSS_RESOURCES.render(
    css_raw=resources.css_raw,
    css_files=resources.css_files
)

script, div = components({'red': red, 'blue': blue, 'green': green})

html = template.render(js_resources=js_resources,
                       css_resources=css_resources,
                       plot_script=script,
                       plot_div=div)

html_file = 'embed_multiple_responsive.html'

with open(html_file, 'w') as f:
    f.write(html)

view(html_file)
Ejemplo n.º 7
0
dropdown = Dropdown(label="Dropdown button", type="warning", menu=menu)
dropdown.on_click(dropdown_handler)

menu = [("Item 1", "foo"), ("Item 2", "bar"), None, ("Item 3", "baz")]
split = Dropdown(label="Split button", type="danger", menu=menu, default_action="baz")
split.on_click(split_handler)

checkbox_group = CheckboxGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_group.on_click(checkbox_group_handler)

radio_group = RadioGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_group.on_click(radio_group_handler)

checkbox_button_group = CheckboxButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1])
checkbox_button_group.on_click(checkbox_button_group_handler)

radio_button_group = RadioButtonGroup(labels=["Option 1", "Option 2", "Option 3"], active=0)
radio_button_group.on_click(radio_button_group_handler)

vbox = VBox(children=[button, toggle, dropdown, split, checkbox_group, radio_group, checkbox_button_group, radio_button_group])

document.add(vbox)
session.store_document(document)

if __name__ == "__main__":
    link = session.object_link(document.context)
    print("Please visit %s to see the plots" % link)
    view(link)
    print("\npress ctrl-C to exit")
    session.poll_document(document)
Ejemplo n.º 8
0
    <h3>Red - pan with responsive</h3>
    {{ plot_div.red }}
    <h3>Green - pan with resize & responsive (should maintain new aspect ratio)</h3>
    {{ plot_div.green }}
    <h3>Blue - pan no responsive</h3>
    {{ plot_div.blue }}

    {{ plot_script }}
    </body>
</html>
''')

resources = INLINE

js_resources = resources.render_js()
css_resources = resources.render_css()

script, div = components({'red': red, 'blue': blue, 'green': green})

html = template.render(js_resources=js_resources,
                       css_resources=css_resources,
                       plot_script=script,
                       plot_div=div)

html_file = 'embed_multiple_responsive.html'

with open(html_file, 'w') as f:
    f.write(html)

view(html_file)
Ejemplo n.º 9
0
 def run(self, do_view=False, poll_interval=0.5):
     link = self.session.object_link(self.document.context)
     print("Please visit %s to see the plots" % link)
     if do_view: view(link)
     print("\npress ctrl-C to exit")
     self.session.poll_document(self.document)
Ejemplo n.º 10
0
 def run(self, do_view=False, poll_interval=0.5):
     link = self.session.object_link(self.document.context)
     print("Please visit %s to see the plots" % link)
     if do_view: view(link)
     print("\npress ctrl-C to exit")
     self.session.poll_document(self.document)
Ejemplo n.º 11
0
 def after_write_file(self, args, filename, doc):
     if args.show:
         from bokeh.browserlib import view
         view(filename)
Ejemplo n.º 12
0
        new_source_data = sources[year].get('data');
    renderer_source.set('data', new_source_data);
    text_source.set('data', {'year': [String(year)]});
"""
    % js_source_array
)

callback = CustomJS(args=sources, code=code)
slider = Slider(start=years[0], end=years[-1], value=1, step=1, title="Year", callback=callback, name="testy")
callback.args["renderer_source"] = renderer_source
callback.args["slider"] = slider
callback.args["text_source"] = text_source


# Stick the plot and the slider together
layout = vplot(plot, slider)

# Open our custom template
with open("gapminder_template.jinja", "r") as f:
    template = Template(f.read())

# Use inline resources, render the html and open
js_resources = JSResources(mode="inline")
title = "Bokeh - Gapminder Bubble Plot"
html = file_html(layout, None, title, template=template, js_resources=js_resources)

output_file = "gapminder.html"
with open(output_file, "w") as f:
    f.write(html)
view(output_file)
Ejemplo n.º 13
0
                value=1,
                step=1,
                title="Year",
                callback=callback,
                name='testy')
callback.args["slider"] = slider
callback.args["renderer_source"] = renderer_source
callback.args["text_source"] = text_source

# Stick the plot and the slider together
layout = vplot(plot, slider)

# Open our custom template
with open('gapminder_template.jinja', 'r') as f:
    template = Template(f.read())

# Use inline resources, render the html and open
resources = Resources(mode='inline')
template_variables = {'bokeh_min_js': resources.js_raw[0]}
title = "Bokeh - Gapminder Bubble Plot"
html = file_html(layout,
                 resources,
                 title,
                 template=template,
                 template_variables=template_variables)

output_file = 'gapminder.html'
with open(output_file, 'w') as f:
    f.write(html)
view(output_file)