Skip to content

Instantly share code, notes, and snippets.

@rossibarra
Last active November 21, 2018 07:17
Show Gist options
  • Save rossibarra/9908000562ea7dabd6b7cf78276b573c to your computer and use it in GitHub Desktop.
Save rossibarra/9908000562ea7dabd6b7cf78276b573c to your computer and use it in GitHub Desktop.
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
output$distPlot <- renderPlot({
ab10<-function(start,gens,drive){
p=start
pf=p
pm=p
d=drive
pvec=as.numeric()
pvec[1]=p
for(i in 1:gens){
ppm=pm*pf+(pm*(1-pf))/2+(pf*(1-pm))/2
ppf=pm*pf+(1+d)*(pm*(1-pf)+pf*(1-pm))/2
pp=(ppm+ppf)/2
pm=pp
pf=pp
pvec[i+1]=pp
}
return(pvec)
}
sims<-ab10(drive=input$drive,gens=10^input$gens,start=10^input$start)
plot(sims~c(1:length(sims)),cex.lab=1.5,pch=19,xlab="generations",ylab="Ab10 frequency")
})
})
#
# This is the user-interface definition of a Shiny web application. You can
# run the application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Ab10 Fixation Speed"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("drive",
"Strength of Drive:",
min = 0,
max = 1,
value = 0.5),
sliderInput("gens",
"Number of Generations (log10):",
min = 0,
max = 4,
value = 2,
step=0.5),
sliderInput("start",
"Starting Frequency of Ab10 (log10):",
min = -5,
max = 0,
value = -2,
step=0.5)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment