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"W42 State:\n\n```\n{json.dumps(state, indent=2)}\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 W42 App", sidebar=[panel.pane.Markdown(sidebar_content, sizing_mode='stretch_width')], main=[ state_pane, w42_state, ], ).servable()