-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.R
120 lines (93 loc) · 3.02 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
library(shiny)
library(datasets)
library(gridExtra)
library(xlsx)
require(ggplot2)
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
# Return the requested dataset
datasetInput1 <- reactive({
switch(input$dataset1,
"OIL" =df_oil,
"RICE"=df_rice,
"FLOUR" =df_flour,
"BEEF" =df_beef,
"CHEESE" = df_cheese,
"BUTTER" = df_butter)
})
datasetInput2 <- reactive({
switch(input$dataset2,
"Carbohydrate" = 'Carbohydrt_.g.',
"Protein" = 'Protein_.g.',
"Energy" = 'Energy_Kcal')
})
datasetInput3 <- reactive({
switch(input$dataset3,
"Cholesterol" = 'Cholesterol_.mg.',
"Sugar" = 'Sugar_Tot_.g.',
"Fat" = 'FAT_Sat_.g.')
})
datasetInput4 <- reactive({
switch(input$dataset4,
"Vertical" = 2,
"Horizontal" = 1)
})
# Generate a summary of the dataset
output$summary <- renderPrint({
dataset <- datasetInput1()
summary(dataset)
})
# Show the first "n" observations
output$table <- renderTable({
# head(datasetInput1(), n = input$obs)
head(datasetInput1(),100)
})
output$view <- renderPlot({
dataset1 <- datasetInput1()
dataset2 <- datasetInput2()
dataset3 <- datasetInput3()
dataset4 <- datasetInput4()
E1=dataset2
E2=dataset3
col1=dataset4
# Variable name for Title
V = strsplit(E1,"_")
E1_t=sapply(V,function(x) x[1])
if (E1_t == "Energy"){
E1_t=paste(E1_t," Ratings(Kcal)")
}
else{
E1_t=paste(E1_t," Ratings(g)")
}
V = strsplit(E2,"_")
E2_t=sapply(V,function(x) x[1])
if (E2_t == "Cholesterol"){
E2_t=paste(E2_t," Ratings(mg)")
}
else{
E2_t=paste(E2_t," Ratings(g)")
}
p1 <- ggplot(dataset1, aes(x=dataset1$Shrt_Desc,y=dataset1[,E1], group=1)) +
geom_bar(stat = "identity", color="black",fill = "#33FF6E")+
#geom_line(size=1.2, colour="green") +
geom_point(size=2) +
ggtitle(E1_t) +
theme(axis.text=element_text(size=10),
plot.title = element_text(size=15,face="bold"),
axis.title=element_text(size=10,face="bold")) +
theme(legend.text=element_text(size=5)) +
labs(x = "Food", y = "Value")
p2 <- ggplot(dataset1, aes(x=dataset1$Shrt_Desc,y=dataset1[,E2],group=1)) +
geom_bar(stat = "identity", color="black",fill = "#FF7733")+
#geom_line(size=1.2,colour = 'blue') +
geom_point(size=2) +
ggtitle(E2_t) +
theme(axis.text=element_text(size=10),
plot.title = element_text(size=15,face="bold"),
axis.title=element_text(size=10,face="bold")) +
theme(legend.text=element_text(size=5)) +
expand_limits(x = 0, y = 0) +
labs(x = "Food", y = "Value")
grid.arrange(p1,p2, ncol=col1)
})
})