library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
shiny::radioButtons("func_chooser",label="pick a function",
choices = c("sin","cos","sin cos product"),
selected = "sin"),
sliderInput("omega", "omega", value = 1, min = -2, max = 2, step = 0.01),
sliderInput("delta", "delta", value = 1, min = 0, max = 2, step = 0.01),
sliderInput("damping", "damping", value = 1, min = 0.9, max = 1, step = 0.001),
numericInput("length", "length", value = 100)
),
mainPanel(
plotOutput("fig")
)
)
)
server <- function(input, output, session) {
dofunc <- function(x,funchoice){
switch (funchoice,
"sin" = sin(x),
"cos" = cos(x),
"sin cos product" = sin(x)*cos(x)
)
}
t <- reactive(seq(0, input$length, length.out = input$length * 100))
x <- reactive(dofunc(input$omega * t() + input$delta,input$func_chooser) * input$damping ^ t())
y <- reactive(dofunc(t(),input$func_chooser) * input$damping ^ t())
output$fig <- renderPlot({
plot(x(), y(), axes = FALSE, xlab = "", ylab = "", type = "l", lwd = 2)
}, res = 96)
}
shinyApp(ui, server)