#!/usr/bin/env python3 """ Plotly + Pyodide - Fixed Data Display Issue """ import gradio as gr def create_pyodide_interface(): """Create interface with fixed Plotly data handling""" pyodide_html = '''
๐Ÿ”„ Loading Pyodide + Plotly...
''' return pyodide_html # Gradio interface with gr.Blocks() as demo: gr.Markdown("# ๐Ÿ” Plotly Debug Version") gr.Markdown("**Diagnose why data points aren't showing**") pyodide_interface = gr.HTML(create_pyodide_interface()) with gr.Row(): with gr.Column(): code_input = gr.Textbox( value="""# Debug Test - Simple Data import plotly.graph_objects as go import numpy as np print("Creating simple test plot...") # Explicit simple data x_data = [1, 2, 3, 4, 5] y_data = [2, 4, 6, 8, 10] print(f"X data: {x_data}") print(f"Y data: {y_data}") # Create figure step by step fig = go.Figure() # Add trace with explicit parameters fig.add_trace(go.Scatter( x=x_data, y=y_data, mode='markers+lines', name='Test Data', marker=dict( size=12, color='red', symbol='circle' ), line=dict( color='blue', width=3 ) )) # Explicit layout fig.update_layout( title='Debug Test Plot', xaxis=dict(title='X Values', range=[0, 6]), yaxis=dict(title='Y Values', range=[0, 12]), width=700, height=500, showlegend=True ) print("Calling fig.show()...") fig.show()""", lines=20, label="Debug Test Code" ) execute_btn = gr.Button("๐Ÿ” Execute Debug", variant="primary") with gr.Column(): status_display = gr.Textbox( label="Status", interactive=False, lines=4 ) check_btn = gr.Button("๐Ÿ“Š Check") # Simple test examples gr.Markdown(""" ### ๐Ÿงช Progressive Tests: **Test 1 - Minimal:** ```python import plotly.graph_objects as go fig = go.Figure() fig.add_trace(go.Scatter(x=[1,2,3], y=[1,2,3])) fig.show() ``` **Test 2 - With NumPy:** ```python import plotly.graph_objects as go import numpy as np x = np.array([1,2,3,4,5]) y = np.array([1,4,9,16,25]) fig = go.Figure() fig.add_trace(go.Scatter(x=x, y=y, mode='markers')) fig.show() ``` **Test 3 - Express:** ```python import plotly.express as px import pandas as pd df = pd.DataFrame({'x': [1,2,3], 'y': [1,4,9]}) fig = px.scatter(df, x='x', y='y') fig.show() ``` """) execute_btn.click( fn=None, inputs=[code_input], outputs=[status_display], js="(code) => window.executeUserCode ? window.executeUserCode(code) : 'Not ready'" ) check_btn.click( fn=None, inputs=[], outputs=[status_display], js="() => window.checkReady ? (window.checkReady() ? 'โœ… Ready' : 'โณ Loading') : 'โŒ Error'" ) if __name__ == "__main__": demo.launch(server_name="0.0.0.0", server_port=7860, share=False)