This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(deSolve) | |
library(ggplot2) | |
# Define server logic required to plot various variables | |
shinyServer(function(input, output) { | |
solveLorenz <- function(pars, times=tout) { | |
derivs <- function(t, state, pars) { # returns rate of change | |
with(as.list(c(state, pars)), { | |
dX <- A*X + Y*Z | |
dY <- B * (Y-Z) | |
dZ <- -X*Y +C*Y -Z | |
return(list(c(dX, dY, dZ))) | |
} | |
) | |
} | |
state <- c(X = 34.848292, Y = 14.331027983, Z = 14.327178391) # originally X = 1, Y = 1, Z = 1 | |
## ode solves the model by integration... | |
return(ode(y = state, times = times, func = derivs, parms = pars)) | |
} | |
output$guessPlot <- reactivePlot(function() { | |
tout<-seq(0, input$tmax, by = .01) | |
guess_pars<-c(A = input$A, B = input$B, C = input$C) | |
# alpha<-input$alpha | |
guess <- as.data.frame(solveLorenz(guess_pars, tout)) | |
print(ggplot(as.data.frame(guess)) + geom_path(aes(X, Y, col=Z), alpha=input$alpha, lwd=.3)) | |
# plot(guess$X, guess$Y) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
# Define UI | |
shinyUI(pageWithSidebar( | |
# Application title | |
headerPanel("Test Lorentz's Equations"), | |
# Sidebar with controls | |
sidebarPanel( | |
numericInput("tmax", "T:", 100), | |
numericInput("alpha", "alpha:", 0.3), | |
numericInput("A", "A:", -8/3), | |
numericInput("B", "B:", -10), | |
numericInput("C", "C:", 28) | |
), | |
# Show the plot of the requested variable against mpg | |
mainPanel( | |
plotOutput("guessPlot") | |
) | |
)) |
Very cool.
ReplyDeleteyou are way to good! very nice.
ReplyDeletethanks!
ReplyDelete