now with dependency to viewlib, and sample main.py
This commit is contained in:
parent
e9e33def3f
commit
99763d9881
3 changed files with 3752 additions and 0 deletions
40
main.py
Normal file
40
main.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import panel
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from watt42_viewlib import attach_w42_state
|
||||||
|
|
||||||
|
panel.extension('echarts', 'ace', 'jsoneditor')
|
||||||
|
|
||||||
|
SYSTEM_ID = os.environ.get("WATT42_SYSTEM_ID", "invalid-system-id")
|
||||||
|
API_TOKEN = os.environ.get("WATT42_API_TOKEN", "invalid-api-token")
|
||||||
|
|
||||||
|
w42_state = panel.rx(None)
|
||||||
|
|
||||||
|
attach_w42_state(rx_var=w42_state, system_id=SYSTEM_ID, token=API_TOKEN)
|
||||||
|
|
||||||
|
def state_to_text(state: dict[str, Any]) -> str:
|
||||||
|
return f"## Watt42 State:\n\nTop lines (as json):\n\n```\n{'\n'.join(json.dumps(state, indent=2).split('\n')[:15])}\n```\n\nReplace this with some awesome visuals"
|
||||||
|
|
||||||
|
state_as_text = panel.bind(state_to_text, w42_state)
|
||||||
|
|
||||||
|
state_pane = panel.pane.Markdown(state_as_text, sizing_mode='stretch_width')
|
||||||
|
|
||||||
|
sidebar_content = """
|
||||||
|
This example shows how to build a front end for a Watt42 system: Watt42 API
|
||||||
|
manages the state of the system, this app visualizes it.
|
||||||
|
|
||||||
|
Find instructions on [how to use this example
|
||||||
|
here](https://source.c3.uber5.com/watt42-public/watt42_viewlib/src/branch/main/README.md#how-to-use).
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
_ = panel.template.FastListTemplate(
|
||||||
|
title="Sample Watt42 App",
|
||||||
|
sidebar=[panel.pane.Markdown(sidebar_content, sizing_mode='stretch_width')],
|
||||||
|
main=[
|
||||||
|
state_pane,
|
||||||
|
w42_state,
|
||||||
|
],
|
||||||
|
).servable()
|
||||||
3711
poetry.lock
generated
Normal file
3711
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -7,6 +7,7 @@ readme = "README.md"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.12"
|
python = "^3.12"
|
||||||
|
watt42-viewlib = {git = "https://source.c3.uber5.com/watt42-public/watt42_viewlib.git"}
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue