Source code for neuralib.dashboard.examples.view_figure

from typing import Optional, Union

from bokeh.model import Model
from bokeh.models.widgets.markups import Div
from neuralib.dashboard import View

from .model import list_date

__all__ = ['AnimalFigureView']


[docs] class AnimalFigureView(View): FIGURE_TYPE = ["default", 'other', 'more'] content_title: Div content_date: Div
[docs] def __init__(self, animal: str | None = None, figure: str | None = None): self._animal: None | str | BaseException = animal self._figure: str | None = figure
@property def title(self) -> str: animal = self.current_animal or 'Unknown' return f'Animal {animal}' @property def current_animal(self) -> str | None: if self._animal is None: try: self._animal = self.get_arg('animal')[0] except (OSError, KeyError) as e: self._animal = e if isinstance(self._animal, str): return self._animal else: return None @property def current_figure(self) -> str: if self._figure is None: try: self._figure = self.get_arg('figure')[0] except (OSError, KeyError): self._figure = 'default' return self._figure
[docs] def setup(self) -> Model: animal = self.current_animal if animal is None: animal = '' self.content_title = Div(text=f"animal {self.current_animal} with figure {self.current_figure}") self.content_date = Div(text="Date:<ol>" + "\n".join([ f"<li>{date}</li>" for date in list_date(animal) ]) + "</ol>") from bokeh.layouts import column return column( self.content_title, self.content_date, )