Papillon Engineering Papillon Engineering
  • Home
  • Teaching
  • Outreach
    • K-12 Outreach Hub
    • Linear Regression
    • API Data Challenge
    • Web Scraping
    • Resonance Defender Game
    • Impedance Breaker Game
  • Circuit Analysis
    • Electrical Dashboard
    • Live Circuit Simulator
    • Reactance Calculator
    • Resonance Defender Game
    • Impedance Breaker Game
    • Circuit Problem Generator
  • Simulations
    • Simulations Hub
    • 1951 USAF Optical Resolution Analyzer
    • Live Circuit Simulator
    • Circuit Problem Generator
    • Reactance Calculator
    • Resonance Defender Game
    • Impedance Breaker Game
  • Projects
  • Class Lectures
Circuit Analysis Dashboard
  • Interactive Tools
  • 1. Define the User Interface
  • 2. Define the Server Logic

```pdppxrkzwqpqxiyvjj #| standalone: true #| viewerHeight: 600

from shiny import App, render, ui import numpy as np import matplotlib.pyplot as plt

app_ui = ui.page_fluid( ui.input_slider(“C_uF”, “Capacitance (uF)”, min=10, max=500, value=100, step=10), ui.input_slider(“L_mH”, “Inductance (mH)”, min=1, max=50, value=10, step=1), ui.output_plot(“reactance_plot”) )

def server(input, output, session): @output @render.plot(alt=“Reactance vs Frequency”) def reactance_plot(): C = input.C_uF() * 1e-6 L = input.L_mH() * 1e-3

    f = np.linspace(10, 1000, 500)
    X_C = 1 / (2 * np.pi * f * C)
    X_L = 2 * np.pi * f * L
    
    fig, ax = plt.subplots(figsize=(8, 5))
    ax.plot(f, X_C, label='Capacitive Reactance ($X_C$)', color='#0072B2', linewidth=2.5)
    ax.plot(f, X_L, label='Inductive Reactance ($X_L$)', color='#D55E00', linewidth=2.5)
    
    f_res = 1 / (2 * np.pi * np.sqrt(L * C))
    if f_res <= 1000:
        X_res = 2 * np.pi * f_res * L
        ax.plot(f_res, X_res, 'ko', markersize=8, label=f'Resonance ({f_res:.1f} Hz)')
        
    ax.set_title('Reactance vs Frequency', fontsize=14, fontweight='bold')
    ax.set_xlabel('Frequency (Hz)', fontsize=12)
    ax.set_ylabel('Reactance (Ohms)', fontsize=12)
    ax.set_ylim(0, 150)
    ax.grid(True, linestyle='--', alpha=0.7)
    ax.legend(fontsize=11)
    
    return fig

app = App(app_ui, server)