Skip to content

Commit

Permalink
improve the style of the live_info widget, closes #250
Browse files Browse the repository at this point in the history
Based on the default style of the Jupyterlab table.
  • Loading branch information
basnijholt committed Dec 18, 2019
1 parent 0295879 commit 7e5f030
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions adaptive/notebook_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ async def update():

runner.ioloop.create_task(update())

display(
ipywidgets.HBox(
(status, cancel),
layout=ipywidgets.Layout(
border="solid 1px", width="200px", align_items="center"
),
)
)
display(ipywidgets.HBox((status, cancel)))


def _table_row(i, key, value):
"""Style the rows of a table. Based on the default Jupyterlab table style."""
style_odd = "text-align: right; padding: 0.5em 0.5em; line-height: 1.0;"
style_even = style_odd + "background: var(--md-grey-100);"
template = '<tr><th style="{style}">{key}</th><th style="{style}">{value}</th></tr>'
style = style_odd if i % 2 == 1 else style_even
return template.format(style=style, key=key, value=value)


def _info_html(runner):
Expand All @@ -260,11 +262,10 @@ def _info_html(runner):
with suppress(Exception):
info.append(("latest loss", f'{runner.learner._cache["loss"]:.3f}'))

template = '<dt class="ignore-css">{}</dt><dd>{}</dd>'
table = "\n".join(template.format(k, v) for k, v in info)
table = "\n".join(_table_row(i, k, v) for i, (k, v) in enumerate(info))

return f"""
<dl>
<table>
{table}
</dl>
</table>
"""

0 comments on commit 7e5f030

Please sign in to comment.