-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsine.qmd
49 lines (38 loc) · 1.09 KB
/
sine.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: Sine function
format: html
filters:
- shinylive
---
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-python}
#| standalone: true
#| viewerHeight: 420
from shiny import App, render, ui
import numpy as np
import matplotlib.pyplot as plt
app_ui = ui.page_fluid(
ui.layout_sidebar(
ui.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.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)
```