@@ -4,17 +4,31 @@ shinyServer(function(input,output,session){
4
4
5
5
source(" ./dev.R" )
6
6
7
+ p <- reactive({as.numeric(unlist(strsplit(input $ p ," ," )))})
8
+ n <- reactive({as.numeric(unlist(strsplit(input $ n ," ," )))})
9
+
10
+ # run single sim
7
11
sim.data <- eventReactive(input $ go ,ignoreNULL = F ,{
8
12
validate(
13
+ need((input $ nPop == length(p())| length(p())== 1 )," number of populations must equal number of starting allele frequencies." ),
9
14
need(input $ gen < 5001 ," Please select < 5000 generations." ),
10
15
need(input $ nPop < 101 ," Please select < 100 populations" ),
11
16
need(input $ n < 1000001 ," Please select n < 1,000,000" ),
12
17
need(input $ plotStats != " " ," Select a variable to plot." )
13
18
)
14
- runPopSim(gen = input $ gen ,p = input $ p ,Waa = input $ Waa ,Wab = input $ Wab ,Wbb = input $ Wbb ,n = input $ n ,
15
- nPop = input $ nPop ,m = input $ m ,stats = input $ plotStats ,infinitePop = input $ infinitePop ,Uab = input $ Uab ,Uba = input $ Uab )
19
+ tmp <- runPopSim(gen = input $ gen ,p = p(),Waa = input $ Waa ,Wab = input $ Wab ,Wbb = input $ Wbb ,n = n(),
20
+ nPop = input $ nPop ,m = input $ m ,stats = input $ plotStats ,infinitePop = input $ infinitePop ,Uab = input $ Uab ,Uba = input $ Uab ,
21
+ continue = F )
22
+ tmp
16
23
})
17
24
25
+ # continue sim
26
+ # sim.data <- eventReactive(input$continue,ignoreNULL = F,{
27
+ # runPopSim(gen=input$gen,p=input$p,Waa=input$Waa,Wab=input$Wab,Wbb=input$Wbb,n=input$n,
28
+ # nPop=input$nPop,m=input$m,stats=input$plotStats,infinitePop=input$infinitePop,Uab=input$Uab,Uba=input$Uab,
29
+ # continue=T)
30
+ # })
31
+
18
32
plot.data <- eventReactive(sim.data(),{
19
33
meltPlotData(allele.freq.df = sim.data(),gen = input $ gen ,nPop = input $ nPop ,stats = input $ plotStats )
20
34
})
@@ -34,50 +48,54 @@ shinyServer(function(input,output,session){
34
48
nLost.text()
35
49
})
36
50
37
- output $ endStateTable <- renderTable({
38
- endState <- sim.data()[input $ gen ,c(" Fis" ," Hs" ," Ht" ," Fst" )]
51
+ endStateTable <- eventReactive(sim.data(),{
52
+ # pNames <- c()
53
+ # for(i in 1:input$nPop){pNames[i] <- paste0("p",i)}
54
+ sim.data()[(input $ gen + 1 ),c(" Fis" ," Hs" ," Ht" ," Fst" )]
39
55
})
40
56
41
- sumTable <- eventReactive(input $ runSim ,{
42
- validate(
43
- need(input $ n < = 100000 ," Please select n <= 100,000" )
44
- )
45
- sumTable <- data.frame (matrix (ncol = 14 ))
46
- withProgress(message = " simulating populations..." ,value = 0 ,{
47
- for (i in 1 : 100 ){
48
- df <- runPopSim2(gen = 100 ,p = input $ p ,Waa = input $ Waa ,Wab = input $ Wab ,Wbb = input $ Wbb ,n = input $ n ,
49
- nPop = 2 ,m = input $ m ,infinitePop = input $ infinitePop ,Uab = input $ Uab ,Uba = input $ Uab )
50
- names(sumTable ) <- names(df )
51
- sumTable [i ,] <- df [nrow(df ),]
52
- incProgress(1 / 100 )
53
- }
54
- })
55
- sumTable
56
- })
57
-
58
- meanTable <- reactive({
59
- tbl <- colMeans(sumTable(),na.rm = T )
60
- tbl <- tbl [c(" Fis" ," Hs" ," Ht" ," Fst" )]
61
- t(tbl )
62
- })
63
-
64
- varTable <- reactive({
65
- tbl <- apply(sumTable(),2 ,function (e ) var(e ,na.rm = T ))
66
- tbl <- tbl [c(" Fis" ," Hs" ," Ht" ," Fst" )]
67
- t(tbl )
57
+ output $ endStateTable <- renderTable({
58
+ endStateTable()
68
59
})
69
60
70
-
71
-
72
- output $ meanTable <- renderTable(meanTable(),colnames = T ,digits = 4 ,caption = " Mean state at final generation:" ,
73
- caption.placement = getOption(" xtable.caption.placement" , " top" ),
74
- caption.width = getOption(" xtable.caption.width" , NULL ))
75
-
76
- output $ varTable <- renderTable(varTable(),colnames = T ,digits = 4 ,caption = " Variance:" ,
77
- caption.placement = getOption(" xtable.caption.placement" , " top" ),
78
- caption.width = getOption(" xtable.caption.width" , NULL ))
79
-
80
- output $ sumTable <- renderTable(sumTable(),caption = " Final Generation States:" ,
81
- caption.placement = getOption(" xtable.caption.placement" , " top" ),
82
- caption.width = getOption(" xtable.caption.width" , NULL ))
61
+ # sumTable <- eventReactive(input$runSim,{
62
+ # validate(
63
+ # need(input$n<=100000,"Please select n <= 100,000")
64
+ # )
65
+ # sumTable <- data.frame(matrix(ncol=14))
66
+ # withProgress(message="simulating populations...",value=0,{
67
+ # for(i in 1:100){
68
+ # df <- runPopSim2(gen=100,p=input$p,Waa=input$Waa,Wab=input$Wab,Wbb=input$Wbb,n=input$n,
69
+ # nPop=2,m=input$m,infinitePop=input$infinitePop,Uab=input$Uab,Uba=input$Uab)
70
+ # names(sumTable) <- names(df)
71
+ # sumTable[i,] <- df[nrow(df),]
72
+ # incProgress(1/100)
73
+ # }
74
+ # })
75
+ # sumTable
76
+ # })
77
+ #
78
+ # meanTable <- reactive({
79
+ # tbl <- colMeans(sumTable(),na.rm=T)
80
+ # tbl <- tbl[c("Fis","Hs","Ht","Fst")]
81
+ # t(tbl)
82
+ # })
83
+ #
84
+ # varTable <- reactive({
85
+ # tbl <- apply(sumTable(),2,function(e) var(e,na.rm=T))
86
+ # tbl <- tbl[c("Fis","Hs","Ht","Fst")]
87
+ # t(tbl)
88
+ # })
89
+ #
90
+ # output$meanTable <- renderTable(meanTable(),colnames = T,digits=4,caption = "Mean state at final generation:",
91
+ # caption.placement = getOption("xtable.caption.placement", "top"),
92
+ # caption.width = getOption("xtable.caption.width", NULL))
93
+ #
94
+ # output$varTable <- renderTable(varTable(),colnames = T,digits=4,caption = "Variance:",
95
+ # caption.placement = getOption("xtable.caption.placement", "top"),
96
+ # caption.width = getOption("xtable.caption.width", NULL))
97
+ #
98
+ # output$sumTable <- renderTable(sumTable(),caption = "Final Generation States:",
99
+ # caption.placement = getOption("xtable.caption.placement", "top"),
100
+ # caption.width = getOption("xtable.caption.width", NULL))
83
101
})
0 commit comments