101 lines
3.0 KiB
Python
101 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Dashboard Callback - Simple test to verify Dash callbacks work
|
|
"""
|
|
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
# Add project root to path
|
|
project_root = Path(__file__).parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
import dash
|
|
from dash import dcc, html, Input, Output
|
|
import plotly.graph_objects as go
|
|
from datetime import datetime
|
|
|
|
# Setup logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def create_test_dashboard():
|
|
"""Create a simple test dashboard to verify callbacks work"""
|
|
|
|
app = dash.Dash(__name__)
|
|
|
|
app.layout = html.Div([
|
|
html.H1("🧪 Test Dashboard - Callback Verification", className="text-center"),
|
|
html.Div([
|
|
html.H3(id="current-time", className="text-center"),
|
|
html.H4(id="counter", className="text-center"),
|
|
dcc.Graph(id="test-chart")
|
|
]),
|
|
dcc.Interval(
|
|
id='test-interval',
|
|
interval=1000, # 1 second
|
|
n_intervals=0
|
|
)
|
|
])
|
|
|
|
@app.callback(
|
|
[
|
|
Output('current-time', 'children'),
|
|
Output('counter', 'children'),
|
|
Output('test-chart', 'figure')
|
|
],
|
|
[Input('test-interval', 'n_intervals')]
|
|
)
|
|
def update_test_dashboard(n_intervals):
|
|
"""Test callback function"""
|
|
try:
|
|
logger.info(f"🔄 Test callback triggered, interval: {n_intervals}")
|
|
|
|
current_time = datetime.now().strftime("%H:%M:%S")
|
|
counter = f"Updates: {n_intervals}"
|
|
|
|
# Create simple test chart
|
|
fig = go.Figure()
|
|
fig.add_trace(go.Scatter(
|
|
x=list(range(n_intervals + 1)),
|
|
y=[i**2 for i in range(n_intervals + 1)],
|
|
mode='lines+markers',
|
|
name='Test Data'
|
|
))
|
|
fig.update_layout(
|
|
title=f"Test Chart - Update #{n_intervals}",
|
|
template="plotly_dark"
|
|
)
|
|
|
|
return current_time, counter, fig
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error in test callback: {e}")
|
|
return "Error", "Error", {}
|
|
|
|
return app
|
|
|
|
def main():
|
|
"""Run the test dashboard"""
|
|
logger.info("🧪 Starting test dashboard...")
|
|
|
|
try:
|
|
app = create_test_dashboard()
|
|
logger.info("✅ Test dashboard created")
|
|
|
|
logger.info("🚀 Starting test dashboard on http://127.0.0.1:8052")
|
|
logger.info("If you see updates every second, callbacks are working!")
|
|
logger.info("Press Ctrl+C to stop")
|
|
|
|
app.run(host='127.0.0.1', port=8052, debug=True)
|
|
|
|
except KeyboardInterrupt:
|
|
logger.info("Test dashboard stopped by user")
|
|
except Exception as e:
|
|
logger.error(f"❌ Error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
main() |