library(shiny) source('barbell.R') xlim <- c(-10,10) ylim <- c(-5,15) function(input, output, session) { output$description <- renderUI(list( h2("Q: Can you tell whether the barbell will and up in A--B ('heads') or B--A ('tails') position?"))) observeEvent({ list(input$x, input$l, input$HookeConstant, input$AirResistance, input$omega, input$resetTime) }, { session$userData$currentBarbell = barbell( p = 0, x = input$x, omega = input$omega, l = input$l, HookeConstant = input$HookeConstant, AirResistance = input$AirResistance, t = 0) }) out <- eventReactive( input$animation, { session$userData$currentBarbell$draw()$evolve() }) output$plot <- renderPlot({ plot(NULL, type=NULL, xlim=xlim, ylim=ylim, xlab='x', ylab='y', asp=1) out() }, height = 960, width = 960 ) output$animationSlider <- renderUI( sliderInput("animation", label= h3("Animate"), min = 0, max = 1000, value = 0, step = 5, animate = animationOptions(interval = input$frameInterval, loop = TRUE) ) ) }