gogo2/test_callback_structure.py
Dobromir Popov 378e88be06 wip
2025-05-26 22:46:55 +03:00

75 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""
Test callback structure to verify it works
"""
import dash
from dash import dcc, html, Input, Output
import plotly.graph_objects as go
from datetime import datetime
import logging
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Create Dash app
app = dash.Dash(__name__)
# Simple layout matching the enhanced dashboard structure
app.layout = html.Div([
html.H1("Callback Structure Test"),
html.Div(id="test-output-1"),
html.Div(id="test-output-2"),
html.Div(id="test-output-3"),
dcc.Graph(id="test-chart"),
dcc.Interval(id='test-interval', interval=3000, n_intervals=0)
])
# Callback using the EXACT same structure as enhanced dashboard
@app.callback(
[
Output('test-output-1', 'children'),
Output('test-output-2', 'children'),
Output('test-output-3', 'children'),
Output('test-chart', 'figure')
],
[Input('test-interval', 'n_intervals')]
)
def update_test_dashboard(n_intervals):
"""Test callback with same structure as enhanced dashboard"""
try:
logger.info(f"Test callback triggered: {n_intervals}")
# Simple outputs
output1 = f"Output 1: {n_intervals}"
output2 = f"Output 2: {datetime.now().strftime('%H:%M:%S')}"
output3 = f"Output 3: Working"
# Simple chart
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4, 5],
y=[n_intervals, n_intervals+1, n_intervals+2, n_intervals+1, n_intervals],
mode='lines',
name='Test Data'
))
fig.update_layout(
title=f"Test Chart - Update {n_intervals}",
template="plotly_dark"
)
logger.info(f"Returning: {output1}, {output2}, {output3}, <Figure>")
return output1, output2, output3, fig
except Exception as e:
logger.error(f"Error in test callback: {e}")
import traceback
logger.error(f"Traceback: {traceback.format_exc()}")
# Return safe fallback
return f"Error: {str(e)}", "Error", "Error", go.Figure()
if __name__ == "__main__":
logger.info("Starting callback structure test on port 8053...")
app.run(host='127.0.0.1', port=8053, debug=True)