neuralib.dashboard.base.View

class neuralib.dashboard.base.View[source]

Bases: object

Top View of bokeh application.

Example

>>> class Top(View):
...     # custom viewer, it often follows a Figure
...     view_a: ViewA # class ViewA(ViewComponent)
...     figure_a: Figure
...
...     # exported UI components, put here if it needs to be access by controller functions
...     select_a: Select
...
...     def setup(self):
...         # initialize custom viewer
...         self.figure_a = Figure(...)
...         self.view_a = ViewA()
...         self.view_a.plot(self.figure_a)
...
...         # initialize exported UI components
...         self.select_a = Select(...)
...         self.select_a.on_change('value', on_select_a) # bind 'value' change event listener
...
...         # local UI components
...         # for those simple UIs without complex interaction, such as Button
...         button_a = Button('A')
...         button_a.on_click(on_btn_a) # bind pressed event listener
...
...         # layout UI components
...         from bokeh.layouts import row, column
...         return column(
...             self.figure_a,
...             row(self.select_a, button_a)
...         )

Implement Note

View instance should be singleton, which means there is no second instance existed in the same application/python runtime. It is a soft rule (which means you can break this rule without and error happen), and this class don’t have any mechanism to ensure this rule.

This class don’t force the __init__() function signature, which means you can define your own __init__ function with custom parameters, such as arguments from the CLI.

Beside top level updating function update(), you can define your own updating functions for only smaller group of UI components.

You can declare all the UI components inside the View class, but you probably will get a mess code. Hence, ViewComponent is used to group related functions together, included some controller functions and data processing functions. By this way, such as variable view_a in the example, it also provides a namespace that make the code more readable.

__init__()

Methods

__init__()

get_arg(key)

on_message(message, reset)

for logging purpose.

run_later(callback, *args, **kwargs)

run_periodic(cycle, callback, *args, **kwargs)

run_timeout(delay, callback, *args, **kwargs)

setup()

setup application top view.

update()

Top level UI components updating function.

Attributes

title

document

document: Document
property title: str
get_arg(key)[source]
Parameters:

key (str)

Return type:

list[str]

abstractmethod setup()[source]

setup application top view. This function is called by BokehServer only once when the server created and opened the web browser.

In this function, you need to initialize the UI components and return the layout.

Return type:

Model

update()[source]

Top level UI components updating function. This function is called by BokehServer when setup() has done.

In this function, you need to initialize the data and update the UI components’ state.

run_later(callback, *args, **kwargs)[source]
Parameters:

callback (Callable)

run_timeout(delay, callback, *args, **kwargs)[source]
Parameters:
  • delay (int)

  • callback (Callable)

run_periodic(cycle, callback, *args, **kwargs)[source]
Parameters:
  • cycle (int)

  • callback (Callable)

on_message(message, reset)[source]

for logging purpose. i.e., TextAreaInput bokeh widget

Parameters:
  • message (str)

  • reset (bool)