Interactive Panel App with rx
#
A dynamic sine curve that updates based on user-controlled amplitude and frequency. This example uses pn.rx()
to link Panel widgets with a plotting function.
import numpy as np
import pandas as pd
import hvplot.pandas # noqa
import panel as pn
x = np.linspace(0, 4 * np.pi, 200)
df = pd.DataFrame({'x': x})
amp_slider = pn.widgets.FloatSlider(
name='Amplitude', start=-5.0, end=5.0,
step=0.1, value=1.0, width=200,
)
freq_slider = pn.widgets.FloatSlider(
name='Frequency', start=0.1, end=5.1,
step=0.1, value=1.0, width=200,
)
def sine_plot(amplitude, frequency):
df['y'] = amplitude * np.sin(frequency * df['x'])
return df.hvplot.line(
x='x', y='y', title='Interactive Sine Wave',
frame_width=400,
)
pn.rx(sine_plot)(amp_slider, freq_slider)
This web page was generated from a Jupyter notebook and not all
interactivity will work on this website.