Python bokeh.models.Div() Examples
The following are 30
code examples of bokeh.models.Div().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bokeh.models
, or try the search function
.
Example #1
Source File: annotation.py From holoviews with BSD 3-Clause "New" or "Revised" License | 6 votes |
def initialize_plot(self, ranges=None, plot=None, plots=None, source=None): """ Initializes a new plot object with the last available frame. """ # Get element key and ranges for frame element = self.hmap.last key = self.keys[-1] self.current_frame = element self.current_key = key data, _, _ = self.get_data(element, ranges, {}) div = BkDiv(text=data, width=self.width, height=self.height) self.handles['plot'] = div self._execute_hooks(element) self.drawn = True return div
Example #2
Source File: test_card.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_card_get_root_title(document, comm): div1 = Div() div2 = Div() layout = Card(div1, div2, title='Test') model = layout.get_root(document, comm=comm) ref = model.ref['id'] header = layout._header_layout._models[ref][0] assert isinstance(model, CardModel) assert model.children == [header, div1, div2] assert header.children[0].text == "Test" div3 = Div() layout.header = div3 assert header.children[0] is div3 layout.header = None assert header.children[0].text == "Test"
Example #3
Source File: test_base.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_layout_setitem_replace_slice(panel, document, comm): div1 = Div() div2 = Div() div3 = Div() layout = panel(div1, div2, div3) p1, p2, p3 = layout.objects model = layout.get_root(document, comm=comm) assert p1._models[model.ref['id']][0] is model.children[0] div3 = Div() div4 = Div() layout[1:] = [div3, div4] assert model.children == [div1, div3, div4] assert p2._models == {} assert p3._models == {}
Example #4
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_gridspec_fixed_with_replacement_pane(document, comm): slider = IntSlider(start=0, end=2) @depends(slider) def div(value): return Div(text=str(value)) gspec = GridSpec() gspec[0, 0:2] = Div() gspec[1, 2] = div model = gspec.get_root(document, comm=comm) ((div1, _, _, _, _), (row, _, _, _, _)) = model.children div2 = row.children[0] assert div1.width == 400 assert div1.height == 300 assert div2.width == 200 assert div2.height == 300 slider.value = 1 assert row.children[0] is not div2 assert row.children[0].width == 200 assert row.children[0].height == 300
Example #5
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_gridspec_stretch_with_replacement_pane(document, comm): slider = IntSlider(start=0, end=2) @depends(slider) def div(value): return Div(text=str(value)) gspec = GridSpec(sizing_mode='stretch_width') gspec[0, 0:2] = Div() gspec[1, 2] = div model = gspec.get_root(document, comm=comm) ((div1, _, _, _, _), (row, _, _, _, _)) = model.children div2 = row.children[0] assert div1.sizing_mode == 'stretch_width' assert div1.height == 300 assert div2.sizing_mode == 'stretch_width' assert div2.height == 300 slider.value = 1 assert row.children[0] is not div2 assert row.children[0].sizing_mode == 'stretch_width' assert row.children[0].height == 300
Example #6
Source File: test_interact.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_interact_replaces_panel(document, comm): def test(a): return a if a else BkDiv(text='Test') interact_pane = interactive(test, a=False) widget = interact_pane._widgets['a'] assert isinstance(widget, widgets.Checkbox) assert widget.value == False column = interact_pane.layout.get_root(document, comm=comm) assert isinstance(column, BkColumn) div = column.children[1].children[0] assert div.text == 'Test' widget.value = True div = column.children[1].children[0] assert div.text == '<pre>True</pre>'
Example #7
Source File: test_slider.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_discrete_slider_options_dict(document, comm): options = OrderedDict([('0.1', 0.1), ('1', 1), ('10', 10), ('100', 100)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=options) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider.value = 100 assert widget.value == 3
Example #8
Source File: test_slider.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_discrete_slider(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider.value = 100 assert widget.value == 3
Example #9
Source File: test_plot.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_bokeh_pane(document, comm): div = Div() pane = Pane(div) # Create pane row = pane.get_root(document, comm=comm) assert isinstance(row, BkRow) assert len(row.children) == 1 model = row.children[0] assert model is div assert pane._models[row.ref['id']][0] is model # Replace Pane.object div2 = Div() pane.object = div2 new_model = row.children[0] assert new_model is div2 assert pane._models[row.ref['id']][0] is new_model # Cleanup pane._cleanup(row) assert pane._models == {}
Example #10
Source File: test_accordion.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_accordion_implicit_constructor(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') accordion = Accordion(p1, p2) model = accordion.get_root(document, comm=comm) assert isinstance(model, BkColumn) assert len(model.children) == 2 assert all(isinstance(c, Card) for c in model.children) card1, card2 = model.children assert card1.children[0].children[0].text == p1.name == 'Div1' assert card1.children[1] is div1 assert card2.children[0].children[0].text == p2.name == 'Div2' assert card2.children[1] is div2
Example #11
Source File: test_accordion.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_accordion_constructor_with_named_objects(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') accordion = Accordion(('Tab1', p1), ('Tab2', p2)) model = accordion.get_root(document, comm=comm) assert isinstance(model, BkColumn) assert len(model.children) == 2 assert all(isinstance(c, Card) for c in model.children) card1, card2 = model.children assert card1.children[0].children[0].text == 'Tab1' assert card1.children[1] is div1 assert card2.children[0].children[0].text == 'Tab2' assert card2.children[1] is div2
Example #12
Source File: test_reactive.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_link_properties_nb(document, comm): class ReactiveLink(Reactive): text = param.String(default='A') obj = ReactiveLink() div = Div() # Link property and check bokeh js property callback is defined obj._link_props(div, ['text'], document, div, comm) assert 'text' in div._callbacks # Assert callback is set up correctly cb = div._callbacks['text'][0] assert isinstance(cb, partial) assert cb.args == (document, div.ref['id']) assert cb.func == obj._comm_change
Example #13
Source File: test_accordion.py From panel with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_accordion_constructor(document, comm): div1 = Div() div2 = Div() accordion = Accordion(('Div1', div1), ('Div2', div2)) p1, p2 = accordion.objects model = accordion.get_root(document, comm=comm) assert isinstance(model, BkColumn) assert len(model.children) == 2 assert all(isinstance(c, Card) for c in model.children) card1, card2 = model.children assert card1.children[0].children[0].text == 'Div1' assert card1.children[1] is div1 assert card2.children[0].children[0].text == 'Div2' assert card2.children[1] is div2
Example #14
Source File: parallel_coordinates.py From CAVE with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _plot_budget(self, df): limits = OrderedDict([('cost', {'lower': df['cost'].min(), 'upper': df['cost'].max()})]) for hp in self.runscontainer.scenario.cs.get_hyperparameters(): if isinstance(hp, NumericalHyperparameter): limits[hp.name] = {'lower': hp.lower, 'upper': hp.upper} if hp.log: limits[hp.name]['log'] = True elif isinstance(hp, CategoricalHyperparameter): # We pass strings as numbers and overwrite the labels df[hp.name].replace({v: i for i, v in enumerate(hp.choices)}, inplace=True) limits[hp.name] = {'lower': 0, 'upper': len(hp.choices) - 1, 'choices': hp.choices} else: raise ValueError("Hyperparameter %s of type %s causes undefined behaviour." % (hp.name, type(hp))) p = parallel_plot(df=df, axes=limits, color=df[df.columns[0]], palette=Viridis256) div = Div(text="Select up and down column grid lines to define filters. Double click a filter to reset it.") plot = column(div, p) return plot
Example #15
Source File: ui.py From nlp-architect with Apache License 2.0 | 5 votes |
def _create_header(train_dropdown, inference_dropdown, text_status) -> layouts.Row: """Utility function for creating and styling the header row in the UI layout.""" architect_logo = Div( text='<a href="http://nlp_architect.nervanasys.com"> <img border="0" ' 'src="style/nlp_architect.jpg" width="200"></a> by IntelĀ® AI Lab', style={ "margin-left": "500px", "margin-top": "20px", "font-size": "110%", "text-align": "center", }, ) css_link = Div( text="<link rel='stylesheet' type='text/css' href='style/lexicon_manager.css'>", style={"font-size": "0%"}, ) js_script = Div(text="<input type='file' id='inputOS' hidden='true'>") title = Div( text="ABSApp", style={ "font-size": "300%", "color": "royalblue", "font-weight": "bold", "margin-left": "500px", }, ) return row( column( row(children=[train_dropdown, lexicons_dropdown, inference_dropdown], width=500), row(text_status), ), css_link, js_script, widgetbox(title, width=900, height=84), widgetbox(architect_logo, width=400, height=84), )
Example #16
Source File: absa_solution.py From nlp-architect with Apache License 2.0 | 5 votes |
def _create_header(train_dropdown, inference_dropdown, text_status) -> layouts.Row: """Utility function for creating and styling the header row in the UI layout.""" architect_logo = Div( text='<a href="http://nlp_architect.nervanasys.com"> <img border="0" ' 'src="style/nlp_architect.jpg" width="200"></a> by IntelĀ® AI Lab', style={ "margin-left": "500px", "margin-top": "20px", "font-size": "110%", "text-align": "center", }, ) css_link = Div( text="<link rel='stylesheet' type='text/css' href='style/lexicon_manager.css'>", style={"font-size": "0%"}, ) js_script = Div(text="<input type='file' id='inputOS' hidden='true'>") title = Div( text="ABSApp", style={ "font-size": "300%", "color": "royalblue", "font-weight": "bold", "margin-left": "500px", }, ) return row( column( row(children=[train_dropdown, lexicons_dropdown, inference_dropdown], width=500), row(text_status), ), css_link, js_script, widgetbox(title, width=900, height=84), widgetbox(architect_logo, width=400, height=84), )
Example #17
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_stretch_with_int_setitem(document, comm): div1 = Div() div2 = Div() gspec = GridSpec(sizing_mode='stretch_both') gspec[0, 0] = div1 gspec[1, 1] = div2 model = gspec.get_root(document, comm=comm) assert model.children == [(div1, 0, 0, 1, 1), (div2, 1, 1, 1, 1)] assert div1.sizing_mode == 'stretch_both' assert div2.sizing_mode == 'stretch_both'
Example #18
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridbox_ncols(document, comm): grid_box = GridBox(Div(), Div(), Div(), Div(), Div(), Div(), Div(), Div(), ncols=3) model = grid_box.get_root(document, comm=comm) assert len(model.children) == 8 coords = [ (0, 0, 1, 1), (0, 1, 1, 1), (0, 2, 1, 1), (1, 0, 1, 1), (1, 1, 1, 1), (1, 2, 1, 1), (2, 0, 1, 1), (2, 1, 1, 1) ] for child, coord in zip(model.children, coords): assert child[1:] == coord
Example #19
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_stretch_with_slice_setitem(document, comm): div1 = Div() div2 = Div() gspec = GridSpec(sizing_mode='stretch_both') gspec[0, 0:2] = div1 gspec[1, 2] = div2 model = gspec.get_root(document, comm=comm) assert model.children == [(div1, 0, 0, 1, 2), (div2, 1, 2, 1, 1)] assert div1.sizing_mode == 'stretch_both' assert div2.sizing_mode == 'stretch_both'
Example #20
Source File: test_accordion.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def accordion(document, comm): """Set up a accordion instance""" div1, div2 = Div(), Div() return Accordion(('Tab1', div1), ('Tab2', div2))
Example #21
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_setitem_slice_overlap(): div = Div() gspec = GridSpec(mode='error') gspec[0, :] = div with pytest.raises(IndexError): gspec[0, 1] = div
Example #22
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_setitem_int_overlap(): div = Div() gspec = GridSpec(mode='error') gspec[0, 0] = div with pytest.raises(IndexError): gspec[0, 0] = 'String'
Example #23
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_slice_setitem(): div = Div() gspec = GridSpec() gspec[0, :] = div assert list(gspec.objects) == [(0, None, 1, None)]
Example #24
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_clone(): div = Div() gspec = GridSpec() gspec[0, 0] = div clone = gspec.clone() assert gspec.objects == clone.objects assert gspec.param.get_param_values() == clone.param.get_param_values()
Example #25
Source File: test_grid.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_gridspec_integer_setitem(): div = Div() gspec = GridSpec() gspec[0, 0] = div assert list(gspec.objects) == [(0, 0, 1, 1)]
Example #26
Source File: test_base.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_layout_clone_no_args_no_kwargs(panel): div1 = Div() div2 = Div() layout = panel(div1, div2, width=400, sizing_mode='stretch_height') clone = layout.clone() assert layout.objects[0].object is clone.objects[0].object assert layout.objects[1].object is clone.objects[1].object assert clone.width == 400 assert clone.sizing_mode == 'stretch_height'
Example #27
Source File: testlayoutplot.py From holoviews with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_layout_title(self): hmap1 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)}) hmap2 = HoloMap({a: Image(np.random.rand(10,10)) for a in range(3)}) plot = bokeh_renderer.get_plot(hmap1+hmap2) title = plot.handles['title'] self.assertIsInstance(title, Div) text = ('<span style="color:black;font-family:Arial;font-style:bold;' 'font-weight:bold;font-size:12pt">Default: 0</span>') self.assertEqual(title.text, text)
Example #28
Source File: test_base.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_layout_clone_objects_in_kwargs(panel): div1 = Div() div2 = Div() layout = panel(div1, div2) clone = layout.clone( objects=(div2, div1), width=400, sizing_mode='stretch_height' ) assert layout.objects[0].object is clone.objects[1].object assert layout.objects[1].object is clone.objects[0].object assert clone.width == 400 assert clone.sizing_mode == 'stretch_height'
Example #29
Source File: test_card.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_card_get_root(document, comm): div1 = Div() div2 = Div() layout = Card(div1, div2) model = layout.get_root(document, comm=comm) ref = model.ref['id'] header = layout._header_layout._models[ref][0] assert isinstance(model, CardModel) assert model.children == [header, div1, div2] assert header.children[0].text == "&#8203;"
Example #30
Source File: test_base.py From panel with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_layout_clone_objects_in_args_and_kwargs(panel): div1 = Div() div2 = Div() layout = panel(div1, div2) with pytest.raises(ValueError): layout.clone(div1, objects=div1)