widgets = Column(children=[ Row(children=[ Column(children=[ click_button, disabled_button, toggle, dropdown, dropdown_split, checkbox_group, radio_group, checkbox_button_group, radio_button_group, ]), Column(children=[ text_input, autocomplete_input, select, multi_select, slider, range_slider, date_slider, date_range_slider, spinner, color_picker, date_picker, paragraph, div, pre_text, ]), tabs, ]), table, ]) doc = Document() doc.add_root(widgets) if __name__ == "__main__": doc.validate() filename = "widgets.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Widgets")) print("Wrote %s" % filename) view(filename)
plot.add_layout(LinearAxis(axis_label="default range"), 'below') plot.add_layout(LinearAxis(axis_label="qux range", x_range_name="qux"), 'below') plot.add_layout(LinearAxis(axis_label="default range"), 'left') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'left') plot.add_layout(LinearAxis(axis_label="default range"), 'right') plot.add_layout(LinearAxis(axis_label="foo range", y_range_name="foo"), 'right') circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black") plot.add_glyph(source, circle) circle2 = Circle(x="x", y="y2", fill_color="blue", size=5, line_color="black") plot.add_glyph(source, circle2, y_range_name="foo") plot.add_tools(PanTool(), WheelZoomTool()) doc = Document() doc.add_root(plot) if __name__ == "__main__": doc.validate() filename = "twin_axis.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Twin Axis Plot")) print("Wrote %s" % filename) view(filename)
session = push_session(document) x = linspace(-6 * pi, 6 * pi, 1000) y = sin(x) z = cos(x) source = ColumnDataSource(data=dict(x=x, y=y, z=z)) plot = Plot(x_range=Range1d(-2 * pi, 2 * pi), y_range=DataRange1d(), min_border=50) line_glyph = Line(x="x", y="y", line_color="blue") plot.add_glyph(source, line_glyph) line_glyph2 = Line(x="x", y="z", line_color="red") plot.add_glyph(source, line_glyph2) plot.add_layout(LinearAxis(), "below") plot.add_layout(LinearAxis(), "left") plot.add_tools(PanTool(), WheelZoomTool()) document.add_root(plot) document.validate() print("\nanimating... press ctrl-C to stop") session.show(plot) while True: for i in linspace(-2 * pi, 2 * pi, 50): source.data["x"] = x + i time.sleep(0.1)
def create_layout(): year_select = Select(title="Year:", value="2010", options=years) location_select = Select(title="Location:", value="World", options=locations) year_select.on_change('value', on_year_change) location_select.on_change('value', on_location_change) controls = WidgetBox(children=[year_select, location_select], height=150, width=600) layout = Column(children=[controls, pyramid(), population()]) return layout layout = create_layout() update_data() document.add_root(layout) session.show(layout) if __name__ == "__main__": document.validate() print("\npress ctrl-C to exit") session.loop_until_closed()