from typing import Optional, Union
from bokeh.model import Model
from bokeh.models.widgets.inputs import Select
from bokeh.models.widgets.markups import Div
from neuralib.dashboard import BokehServer, View
from .view_figure import AnimalFigureView
__all__ = ['AnimalView']
[docs]
class AnimalView(View):
select: Select
content: Div
[docs]
def __init__(self, animal: str | None = None):
self._animal: None | str | BaseException = animal
@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
[docs]
def setup(self) -> Model:
self.select = Select(
title='Figure Type',
value='',
options=['', *AnimalFigureView.FIGURE_TYPE]
)
self.select.on_change('value', self.on_figure_type)
self.content = Div(text="", css_classes=['yw-animal-content'])
from bokeh.layouts import column
return column(
self.select,
self.content,
Div(text="""
<style>
div.yw-animal-content div {
position: fixed;
width: 90%;
height: 100%;
}
div.yw-animal-content div iframe.bk {
display: block;
width: 100%;
height: 100%;
}
</style>
""")
)
def main():
import argparse
ap = argparse.ArgumentParser()
ap.add_argument('--animal', metavar='NAME', required=True)
opt = ap.parse_args()
BokehServer().start(AnimalView(opt.animal))
if __name__ == '__main__':
main()