The plot below allows you to control parameters used in the sine function. Experiment with the period, amplitude, and phase shift to see how they affect the graph.
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| components: [editor, viewer]
#| layout: horizontal
#| viewerHeight: 800
from shiny import App, render, ui
import numpy as np
import matplotlib.pyplot as plt
app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.panel_sidebar(
ui.input_slider("period", "Period", 0.5, 2, 1, step=0.5),
ui.input_slider("amplitude", "Amplitude", 0, 2, 1, step=0.25),
ui.input_slider("shift", "Phase shift", 0, 2, 0, step=0.1),
),
ui.panel_main(
ui.output_plot("plot"),
),
),
)
def server(input, output, session):
@output
@render.plot(alt="Sine function")
def plot():
t = np.arange(0.0, 4.0, 0.01)
s = input.amplitude() * np.sin(
(2 * np.pi / input.period()) * (t - input.shift() / 2)
)
fig, ax = plt.subplots()
ax.set_ylim([-2, 2])
ax.plot(t, s)
ax.grid()
app = App(app_ui, server)
this code shows how to access the Shinylive app in from the apps folder using a helper function from the root dierctory.
Citation
BibTeX citation:
@online{bochman2024,
author = {Bochman, Oren},
title = {Sine Function},
date = {2024-12-20},
url = {https://orenbochman.github.io/posts/2024/shinylive/},
langid = {en}
}
For attribution, please cite this work as:
Bochman, Oren. 2024. “Sine Function.” December 20, 2024. https://orenbochman.github.io/posts/2024/shinylive/.