Python bokeh.layouts.layout() Examples

The following are 18 code examples of bokeh.layouts.layout(). 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.layouts , or try the search function .
Example #1
Source File: bokeh_event_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def create(self):
        for _ in range(self.num_cameras):
            cam = BokehEventViewerCamera(self)
            cam.enable_pixel_picker(self.num_waveforms)
            cam.create_view_widget()
            cam.update_view_widget()
            cam.add_colorbar()

            self.cameras.append(cam)
            self.camera_layouts.append(cam.layout)

        for iwav in range(self.num_waveforms):
            wav = BokehEventViewerWaveform(self)
            active_color = self.cameras[0].active_colors[iwav]
            wav.fig.select(name="line")[0].glyph.line_color = active_color
            wav.enable_time_picker()
            wav.create_view_widget()
            wav.update_view_widget()

            self.waveforms.append(wav)
            self.waveform_layouts.append(wav.layout)

        self.layout = layout(
            [[column(self.camera_layouts), column(self.waveform_layouts)],]
        ) 
Example #2
Source File: file_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def finish(self):
        if not self.disable_server:

            def modify_doc(doc):
                doc.add_root(self.layout)
                doc.title = self.name

                directory = os.path.abspath(os.path.dirname(__file__))
                theme_path = os.path.join(directory, "theme.yaml")
                template_path = os.path.join(directory, "templates")
                doc.theme = Theme(filename=theme_path)
                env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_path))
                doc.template = env.get_template("index.html")

            self.log.info(
                "Opening Bokeh application on " "http://localhost:{}/".format(self.port)
            )
            server = Server({"/": modify_doc}, num_procs=1, port=self.port)
            server.start()
            server.io_loop.add_callback(server.show, "/")
            server.io_loop.start() 
Example #3
Source File: visualization.py    From minian with GNU General Public License v3.0 6 votes vote down vote up
def _meta_wgt(self):
        wgt_meta = {d: pnwgt.Select(
            name=d, options=v, height=45, width=120)
                    for d, v in self.meta_dicts.items()}
        def make_update_func(meta_name):
            def _update(x):
                self.metas[meta_name] = x.new
                self.update_subs()
            return _update
        for d, wgt in wgt_meta.items():
            cur_update = make_update_func(d)
            wgt.param.watch(cur_update, 'value')
        wgt_update = pnwgt.Button(
            name='Refresh', button_type='primary', height=30, width=120)
        wgt_update.param.watch(self.update_all, 'clicks')
        wgt_load = pnwgt.Button(
            name='Load Data', button_type='danger', height=30, width=120)
        wgt_load.param.watch(self.compute_subs, 'clicks')
        return pn.layout.WidgetBox(
            *(list(wgt_meta.values()) + [wgt_update, wgt_load]),
            width=150) 
Example #4
Source File: bokeh_event_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_view_widget(self):
        self.w_view = Select(title="View:", value="", options=[], width=5)
        self.w_view.on_change("value", self.on_view_widget_change)
        self.layout = column([self.w_view, self.layout]) 
Example #5
Source File: ui.py    From nlp-architect with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: absa_solution.py    From nlp-architect with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _spatial_all_wgt(self):
        wgt_useAC = pnwgt.Checkbox(
            name='UseAC', value=self._useAC, width=120, height=15)
        def callback_useAC(val):
            self._useAC = val.new
            self.update_AC()
        wgt_useAC.param.watch(callback_useAC, 'value')
        return pn.layout.WidgetBox(wgt_useAC, width=150) 
Example #8
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def show(self):
        return pn.layout.Column(
            self.spatial_all,
            pn.layout.Row(
                pn.layout.Column(
                    pn.layout.Row(
                        self.wgt_meta,
                        self.wgt_spatial_all
                    ),
                    self.wgt_temp_comp),
                self.temp_comp_sub,
                self.wgt_man)) 
Example #9
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _widgets(self):
        dfrange = [0, self._f]
        w_frame = iwgt.IntSlider(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            continuous_update=False,
            description="Frame:",
            layout=iwgt.Layout(width='50%'))
        w_play = iwgt.Play(
            value=0,
            min=dfrange[0],
            max=dfrange[1],
            interval=1000 / self.framerate)
        iwgt.jslink((w_play, 'value'), (w_frame, 'value'))
        iwgt.interactive(self.strm_f.event, x=w_frame)
        uidrange = [0, self._u]
        w_select = iwgt.IntRangeSlider(
            value=self._cur_sel,
            min=uidrange[0],
            max=uidrange[1],
            continuous_update=False,
            description="Unit ID:",
            layout=iwgt.Layout(width='50%'))
        w_select.observe(self._set_sel, names='value')
        w_update = iwgt.Button(description="Update")
        w_update.on_click(self._update_plot)
        w_update_mov = iwgt.Checkbox(
            value=self._update_mov, description="Update Movies")
        w_update_mov.observe(self._set_update, names='value')
        w_overlay = iwgt.Checkbox(value=self._overlay, description="Overlay")
        w_overlay.observe(self._set_overlay, names='value')
        return iwgt.VBox([
            iwgt.HBox([w_frame, w_play, w_update_mov]),
            iwgt.HBox([w_select, w_update, w_overlay])
        ]) 
Example #10
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def _widgets(self):
        w_play = pnwgt.Player(
            length=len(self._f), interval=10,
            value=0, width=650, height=90)
        def play(f):
            if not f.old == f.new:
                self.strm_f.event(f=int(self._f[f.new]))
        w_play.param.watch(play, 'value')
        w_box = pnwgt.Button(
            name='Update Mask',
            button_type='primary',
            width=100,
            height=30)
        w_box.param.watch(self._update_box, 'clicks')
        if not self._layout:
            wgt_meta = {d: pnwgt.Select(
                name=d, options=v, height=45, width=120)
                        for d, v in self.meta_dicts.items()}
            def make_update_func(meta_name):
                def _update(x):
                    self.cur_metas[meta_name] = x.new
                    self._update_subs()
                return _update
            for d, wgt in wgt_meta.items():
                cur_update = make_update_func(d)
                wgt.param.watch(cur_update, 'value')
            wgts = pn.layout.WidgetBox(
                w_box, w_play, *list(wgt_meta.values()))
        else:
            wgts = pn.layout.WidgetBox(
                w_box, w_play)
        return wgts 
Example #11
Source File: visualization.py    From minian with GNU General Public License v3.0 5 votes vote down vote up
def show(self):
        return pn.layout.Column(self.widgets, self.pnplot) 
Example #12
Source File: __init__.py    From arviz with Apache License 2.0 5 votes vote down vote up
def show_layout(ax, show=True, force_layout=False):
    """Create a layout and call bokeh show."""
    if show is None:
        show = rcParams["plot.bokeh.show"]
    if show:
        import bokeh.plotting as bkp

        layout = create_layout(ax, force_layout=force_layout)
        bkp.show(layout) 
Example #13
Source File: file_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self._event = None
        self._event_index = None
        self._event_id = None
        self._telid = None
        self._channel = None

        self.w_next_event = None
        self.w_previous_event = None
        self.w_event_index = None
        self.w_event_id = None
        self.w_goto_event_index = None
        self.w_goto_event_id = None
        self.w_telid = None
        self.w_channel = None
        self.w_dl1_dict = None
        self.wb_extractor = None
        self.layout = None

        self.reader = None
        self.seeker = None
        self.extractor = None
        self.calibrator = None
        self.viewer = None

        self._updating_dl1 = False
        # make sure, gzip files are seekable
        self.config.SimTelEventSource.back_seekable = True 
Example #14
Source File: bokeh_event_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def create_view_widget(self):
        self.w_view = Select(title="View:", value="", options=[], width=5)
        self.w_view.on_change("value", self.on_view_widget_change)
        self.layout = column([self.w_view, self.layout]) 
Example #15
Source File: vrep_costar_stack.py    From costar_plan with Apache License 2.0 4 votes vote down vote up
def next_example(files, action):
    """ load the next example in the dataset
    """
    global file_textbox, button, button_next, button_prev, index, vrep_viz, data, numpy_data
    print("next clicked")
    file_textbox.value = "Processing..."
    renderer = hv.renderer('bokeh')
    if action == 'next':
        index = (index + 1) % len(files)
    else:
        index = (index - 1) % len(files)
    #print("it ", iterator)
    print("index before check", index)
    index = check_errors(files, index, action)
    print("index after check", index)
    print("len", len(files))

    file_name = files[index]
    data, numpy_data = load_example(file_name_list[index])
    rgb_images = numpy_data['rgb_images']
    frame_indices = numpy_data['frame_indices']
    gripper_status = numpy_data['gripper_status']
    action_status = numpy_data['action_status']
    gripper_action_label = numpy_data['gripper_action_label']
    gripper_action_goal_idx = numpy_data['gripper_action_goal_idx']
    print("image loaded")
    print("action goal idx", gripper_action_goal_idx)
    height = int(rgb_images[0].shape[0])
    width = int(rgb_images[0].shape[1])
    start = 0
    end = len(rgb_images)
    print(end)

    def slider_update(attrname, old, new):
        plot.update(slider.value)

    slider = Slider(start=start, end=end, value=0, step=1, title="Frame", width=width)
    slider.on_change('value', slider_update)

    holomap = generate_holo_map(rgb_images, height, width)
    print("generated holomap")
    plot = renderer.get_plot(holomap)
    print("plot rendered")
    gripper_plot, action_plot, gripper_action_plot = load_data_plot(renderer, frame_indices, gripper_status, action_status, gripper_action_label, height, width)
    print("plot loaded..")
    plot_list = [[plot.state], [gripper_plot.state], [action_plot.state]]

    widget_list = [[slider, button, button_prev, button_next], [file_textbox]]

    # "gripper_action" plot, labels based on the gripper opening and closing
    plot_list.append([gripper_action_plot.state])
    layout_child = layout(plot_list + widget_list, sizing_mode='fixed')
    curdoc().clear()
    file_textbox.value = file_name.split("\\")[-1]
    #curdoc().remove_root(layout_child)
    #layout_root.children[0] = layout_child
    curdoc().add_root(layout_child)

#iterator = iter(file_name_list) 
Example #16
Source File: stack_player.py    From costar_plan with Apache License 2.0 4 votes vote down vote up
def next_image(files, action):
    global file_textbox, button, button_next, button_prev, index
    print("next clicked")
    file_textbox.value = "Processing..."
    renderer = hv.renderer('bokeh')
    if action == 'next':
        index=(index + 1) % len(files)
    else:
        index=(index - 1) % len(files)
    #print("it ", iterator)
    print("index before check",index)
    index = check_errors(files, index, action)
    print("index after check", index)
    print("len", len(files))

    file_name = files[index]
    rgb_images, frame_indices, gripper_status, action_status, gripper_action_label, gripper_action_goal_idx = process_image(file_name)
    print("image loaded")
    print("action goal idx", gripper_action_goal_idx)
    height = int(rgb_images[0].shape[0])
    width = int(rgb_images[0].shape[1])
    start = 0
    end = len(rgb_images) - 1
    print(' End Index of RGB images: ' + str(end))

    def slider_update(attrname, old, new):
        plot.update(slider.value)

    slider = Slider(start=start, end=end, value=0, step=1, title="Frame", width=width)
    slider.on_change('value', slider_update)

    holomap = generate_holo_map(rgb_images, height, width)
    print("generated holomap")
    plot = renderer.get_plot(holomap)
    print("plot rendered")
    gripper_plot, action_plot, gripper_action_plot = load_data_plot(renderer, frame_indices, gripper_status, action_status, gripper_action_label, height, width)
    print("plot loaded..")
    plot_list = [[plot.state], [gripper_plot.state], [action_plot.state]]

    widget_list = [[slider, button, button_prev, button_next], [file_textbox]]

    # "gripper_action" plot, labels based on the gripper opening and closing
    plot_list.append([gripper_action_plot.state])
    layout_child = layout(plot_list + widget_list, sizing_mode='fixed')
    curdoc().clear()
    file_textbox.value = file_name.split("\\")[-1]
    #curdoc().remove_root(layout_child)
    #layout_root.children[0] = layout_child
    curdoc().add_root(layout_child)

#iterator = iter(file_name_list) 
Example #17
Source File: __init__.py    From arviz with Apache License 2.0 4 votes vote down vote up
def create_layout(ax, force_layout=False):
    """Transform bokeh array of figures to layout."""
    ax = np.atleast_2d(ax)
    subplot_order = rcParams["plot.bokeh.layout.order"]
    if force_layout:
        from bokeh.layouts import gridplot as layout

        ax = ax.tolist()
        layout_args = {
            "sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"],
            "toolbar_location": rcParams["plot.bokeh.layout.toolbar_location"],
        }
    elif any(item in subplot_order for item in ("row", "column")):
        # check number of rows
        match = re.match(r"(\d*)(row|column)", subplot_order)
        n = int(match.group(1)) if match.group(1) is not None else 1
        subplot_order = match.group(2)
        # set up 1D list of axes
        ax = [item for item in ax.ravel().tolist() if item is not None]
        layout_args = {"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"]}
        if subplot_order == "row" and n == 1:
            from bokeh.layouts import row as layout
        elif subplot_order == "column" and n == 1:
            from bokeh.layouts import column as layout
        else:
            from bokeh.layouts import layout

        if n != 1:
            ax = np.array(ax + [None for _ in range(int(np.ceil(len(ax) / n)) - len(ax))])
            if subplot_order == "row":
                ax = ax.reshape(n, -1)
            else:
                ax = ax.reshape(-1, n)
            ax = ax.tolist()
    else:
        if subplot_order in ("square", "square_trimmed"):
            ax = [item for item in ax.ravel().tolist() if item is not None]
            n = int(np.ceil(len(ax) ** 0.5))
            ax = ax + [None for _ in range(n ** 2 - len(ax))]
            ax = np.array(ax).reshape(n, n)
        ax = ax.tolist()
        if (subplot_order == "square_trimmed") and any(
            all(item is None for item in row) for row in ax
        ):
            from bokeh.layouts import layout

            ax = [row for row in ax if not all(item is None for item in row)]
            layout_args = {"sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"]}
        else:
            from bokeh.layouts import gridplot as layout

            layout_args = {
                "sizing_mode": rcParams["plot.bokeh.layout.sizing_mode"],
                "toolbar_location": rcParams["plot.bokeh.layout.toolbar_location"],
            }
    # ignore "fixed" sizing_mode without explicit width and height
    if layout_args.get("sizing_mode", "") == "fixed":
        layout_args.pop("sizing_mode")
    return layout(ax, **layout_args) 
Example #18
Source File: bokeh_event_viewer.py    From ctapipe with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def __init__(
        self,
        subarray,
        config=None,
        parent=None,
        num_cameras=1,
        num_waveforms=2,
        **kwargs,
    ):
        """
        A class to organise the interface between
        `ctapipe.visualization.bokeh.CameraDisplay`,
        `ctapipe.visualization.bokeh.WaveformDisplay` and
        `ctapipe.core.container.DataContainer`.

        Parameters
        ----------
        config : traitlets.loader.Config
            Configuration specified by config file or cmdline arguments.
            Used to set traitlet values.
            Set to None if no configuration to pass.
        tool : ctapipe.core.Tool
            Tool executable that is calling this component.
            Passes the correct logger to the component.
            Set to None if no Tool to pass.
        num_cameras : int
            Number of camera figures to handle
        num_waveforms : int
            Number of waveform figures to handle
        kwargs
        """
        super().__init__(config=config, parent=parent, **kwargs)

        self._event = None
        self._view = "r0"
        self._telid = None
        self._channel = 0

        self.num_cameras = num_cameras
        self.num_waveforms = num_waveforms

        self.cameras = []
        self.camera_layouts = []
        self.waveforms = []
        self.waveform_layouts = []
        self.subarray = subarray

        self.layout = None