FreddyHernandez commited on
Commit
6d138bb
·
verified ·
1 Parent(s): 5227b9c

Update server.R

Browse files
Files changed (1) hide show
  1. server.R +109 -18
server.R CHANGED
@@ -1,23 +1,114 @@
1
- function(input, output, session) {
 
2
 
3
- # Combine the selected variables into a new data frame
4
- selectedData <- reactive({
5
- iris[, c(input$xcol, input$ycol)]
6
- })
7
 
8
- clusters <- reactive({
9
- kmeans(selectedData(), input$clusters)
10
- })
11
 
12
- output$plot1 <- renderPlot({
13
- palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
14
- "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- par(mar = c(5.1, 4.1, 0, 1))
17
- plot(selectedData(),
18
- col = clusters()$cluster,
19
- pch = 20, cex = 3)
20
- points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
21
- })
 
 
 
 
 
 
 
 
22
 
23
- }
 
 
 
 
 
 
1
+ library(shiny)
2
+ library(ggplot2)
3
 
4
+ source("www/auxiliar_functions.R")
 
 
 
5
 
6
+ # Define server logic required to draw a histogram
7
+ shinyServer(function(input, output) {
 
8
 
9
+ output$distPlot <- renderPlot({
10
+
11
+ if (input$Distribucion == "Normal") {
12
+ p <- ggplot() +
13
+ geom_function(colour="indianred1", fun=dnorm, lwd=2,
14
+ args=list(mean=input$mu_normal, sd=input$sigma)) +
15
+ xlim(input$min_normal, input$max_normal) +
16
+ theme(legend.position = "none") +
17
+ labs(x="X", y="Density",
18
+ title=bquote(paste("X ~ N(",
19
+ mu, "=", .(input$mu_normal),
20
+ ", ",
21
+ sigma^2, "=", .(input$sigma), ")")))
22
+ print(p)
23
+ }
24
+
25
+ if (input$Distribucion == "Gamma") {
26
+ p <- ggplot() +
27
+ geom_function(color="dodgerblue2", fun=dgamma_glm, lwd=2,
28
+ args=list(mu=input$mu_gamma, phi=input$phi_gamma)) +
29
+ xlim(input$min_gamma, input$max_gamma) +
30
+ theme(legend.position = "none") +
31
+ labs(x="X", y="Density",
32
+ title=bquote(paste("X ~ Gamma(",
33
+ mu, "=", .(input$mu_gamma),
34
+ ", ",
35
+ phi, "=", .(input$phi_gamma), ")")))
36
+ print(p)
37
+ }
38
+
39
+ if (input$Distribucion == "Inv. gaussian") {
40
+ p <- ggplot() +
41
+ geom_function(color="darkslategray3", fun=dinvgaus_glm, lwd=2,
42
+ args=list(mu=input$mu_invgaus, phi=input$phi_invgaus)) +
43
+ xlim(input$min_invgaus, input$max_invgaus) +
44
+ theme(legend.position = "none") +
45
+ labs(x="X", y="Density",
46
+ title=bquote(paste("X ~ InvGaussian(",
47
+ mu, "=", .(input$mu_invgaus),
48
+ ", ",
49
+ phi, "=", .(input$phi_invgaus), ")")))
50
+ print(p)
51
+ }
52
+
53
+ if (input$Distribucion == "Binomial") {
54
+ xs <- seq(from=0, to=input$m)
55
+ ys <- dbinom(x=xs, size=input$m, prob=input$mu_binom)
56
+
57
+ p <- ggplot(data=data.frame(x=xs, y=ys,
58
+ yend=rep(0, input$m+1)),
59
+ aes(x=x, y=y, xend=x, yend=yend)) +
60
+ geom_point(colour="mediumpurple1") +
61
+ geom_segment(colour="mediumpurple1") +
62
+ theme(legend.position = "none") +
63
+ labs(x="X", y="Probability",
64
+ title=bquote(paste("X ~ Binomial(",
65
+ n, "=", .(input$m),
66
+ ", ",
67
+ mu, "=", .(input$mu_binom), ")")))
68
+ print(p)
69
+ }
70
+
71
+ if (input$Distribucion == "Poisson") {
72
+ xs <- seq(from=0, to=input$max_pois)
73
+ ys <- dpois(x=xs, lambda=input$mu_pois)
74
+
75
+ p <- ggplot(data=data.frame(x=xs, y=ys,
76
+ yend=rep(0, input$max_pois+1)),
77
+ aes(x=x, y=y, xend=x, yend=yend)) +
78
+ geom_point(colour="lightsalmon2") +
79
+ geom_segment(colour="lightsalmon2") +
80
+ theme(legend.position = "none") +
81
+ labs(x="X", y="Probability",
82
+ title=bquote(paste("X ~ Poisson(",
83
+ mu, "=", .(input$mu_pois),
84
+ # ", ",
85
+ # mu, "=", .(input$mu_binom),
86
+ ")")))
87
+ print(p)
88
+ }
89
+
90
+ if (input$Distribucion == "Negative binomial") {
91
+ xs <- seq(from=0, to=input$max_negbin)
92
+ ys <- dnbinom(x=xs, mu=input$mu_negbin, size=input$k)
93
 
94
+ p <- ggplot(data=data.frame(x=xs, y=ys,
95
+ yend=rep(0, input$k+1)),
96
+ aes(x=x, y=y, xend=x, yend=yend)) +
97
+ geom_point(colour="olivedrab3") +
98
+ geom_segment(colour="olivedrab3") +
99
+ theme(legend.position = "none") +
100
+ labs(x="X", y="Probability",
101
+ title=bquote(paste("X ~ NegBin(",
102
+ mu, "=", .(input$mu_negbin),
103
+ ", ",
104
+ k, "=", .(input$k), ")")))
105
+ print(p)
106
+ }
107
+
108
 
109
+ }, res = 96)
110
+
111
+ })
112
+
113
+
114
+