-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokemonGenerator.R
314 lines (216 loc) · 11.4 KB
/
PokemonGenerator.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
library(tidyverse)
library(shinydashboard)
library(shinyWidgets)
library(dplyr)
library(waffle)
library(shiny)
library(gridExtra)
library(ggplot2)
library(bslib)
library(readxl)
library(DT)
data <- read_csv("Pokemoncsv.csv")
data$`Type 2`<- replace_na(data$`Type 2`, "No")
data$Legendary<- ifelse(data$Legendary =="FALSE","No","Yes")
Barchartcount<-ggplot(data = data, aes(y = `Type 1`,fill = `Type 1`)) +
geom_bar() + theme(legend.position = "none",axis.title =element_text(colour ="#5a5a5a", size = 16)
,axis.text = element_text(size = 12,color = "#5a5a5a")
,axis.title.x = element_blank()
,axis.ticks.y = element_line(colour = "white")
,axis.ticks.x = element_line(colour = "white")
,panel.background = element_rect(fill = "white"
))
Barchartcount2<-ggplot(data = data, aes(y = `Type 2`,fill = `Type 2`)) +
geom_bar() + theme(legend.position = "none",axis.title =element_text(colour ="#5a5a5a",size = 16)
,axis.text = element_text(size = 12,color = "#5a5a5a")
,axis.title.x = element_blank()
,axis.ticks.y = element_line(colour = "white")
,axis.ticks.x = element_line(colour = "white")
,panel.background = element_rect(fill = "white"
))
gen<-c('1' = 20,
'2' = 13,
'3' = 20,
'4' = 15,
'5' = 20,
'6' = 10)
leg<-c("Legendary" =8,
"Non-Legendary" =92 )
wgen<-waffle(gen, rows =5,size=1,colors = c("#D291BC","#FFDFD3","#76BACB",
"#FFAFA3","#CAEAD0","#D1D1D1"))
wwlegend<-waffle(leg, rows =5,size=1,colors = c("#494746","#FAF5EF"),legend_pos = "none")
ui <- fluidPage(
theme = bs_theme(version = 5, bootswatch = "minty"),
titlePanel("What Pokémon will choose you?"),
sidebarLayout(
sidebarPanel(
tags$text("Everytime you hit a button your Pokémon will change!"),
actionButton("actionbutton", label = "Complete",width =130),
actionButton("randombutton", label = "Random",width =100),
tags$hr(),
selectInput('firsttype', "Select your first type", choices = c("Water","Fire","Grass","Electric","Ice","Rock","Poison","Bug","Normal","Fighting","Flying","Psychic","Dragon","Ground","Steel","Ghost","Dark","Fairy"), selected = "Water"),
selectInput('secondtype', "Second Type", choices = c("Random"), selected = "Random"),
sliderInput('health', "Select your health", min = 20,
max = 100, value = 50),
sliderInput("speed", label = h3("Select your Speed"), min = 20,
max = 100, value = 50),
sliderInput("nspeed", label = h3("Select your normal Attack Speed"), min = 20,
max = 100, value = 50),
sliderInput("ndamage", label = h3("Select your normal Damage resistance"), min = 20, max = 100, value = 50),
tags$h1("Select your SPECIAL"),
knobInput(
inputId = "circle1",
label = " Attack speed",
value = 20,
min = 20,
max = 180,
displayPrevious = TRUE,
lineCap = "round",
fgColor = "#3eb489",
inputColor = "#d3d3d3"
),
knobInput(
inputId = "circle2",
label = "Damage Resistance",
value = 20,
min = 20,
max = 200,
displayPrevious = TRUE,
lineCap = "round",
fgColor = "#3eb489",
inputColor = "#d3d3d3"
),
tags$hr()),
mainPanel(
tabsetPanel(
tabPanel("Your Pokémon",tags$h1('Your Pokémon is....',textOutput("p"))
,uiOutput("link")
,tags$hr()
,DT::dataTableOutput("mytable"))
,tabPanel("Visual",tags$text("Receive your Pokémon to see the graphs!")
,tags$h1('Your Pokémon is....',textOutput("p2"))
,tags$hr()
,tags$text("The dotted line is your current Pokémon")
,tags$h3("Frequency of Total Score For All Pokémon")
,plotOutput("distPlot")
,tags$h3("The Percent of Pokémon In Each Generation")
,tags$text("Each box represents 1%","1 = Generation 1")
,plotOutput("distplot3")
,tags$h3("The Percent Of Legendary Pokémon")
,tags$text("Only 8% of Pokémon are Legendary!")
,plotOutput("distplot4")
,tags$h3("The Total Number Of Pokémon For Each Type")
,tags$text("Type 1 on the left")
,plotOutput("distPlo2t")
,tags$hr())
,tabPanel("Help",tags$h1("Guide")
,tags$hr()
,tags$br("ID: Is the ID from the pokédex associated with each Pokémon")
,tags$br("Type1: Is the main type of your Pokémon")
,tags$br("Type2: Is if the Pokémon has a second type.")
,tags$br("HP: Is how healthy your Pokémon is.")
,tags$br("Attack: Is the speed for normal attacks.")
,tags$br("Defense:Is the damage resistance for normal attacks.")
,tags$br("Sp.Atk: Is the speed for special attacks.")
,tags$br("Sp.Def: Is the damage resistance for special attacks.")
,tags$br("Speed: Is how quick your Pokémon moves.")
,tags$br("Generation: Is what generation your Pokémon is apart of.")
,tags$br("Legendary: Is if your Pokémon is a true legend!")
,tags$hr()
,tags$h1('How the Calculator Works')
,tags$hr()
,tags$br("Just because you want the best Pokémon doesn't mean the Pokémon will choose you!")
,tags$br("The Pokémon total is calculated by adding each numeric field for a total value.")
,tags$br("Then your total is converted to a range. Your range is then checked against the Total score for each Pokémon of the same type you choose.")
,tags$br("If your Pokémon type does not have a total score within your range then you will receive a Pokémon with a random total of the same Pokémon Type.")
,tags$br("Your Pokémon type is the first priority!")
,tags$br("The random button will generate a random Pokémon and disregard any input.")
,tags$hr())
,tabPanel("Source",tags$h1('Data Set Source')
,tags$hr()
,tags$a("Data Set",href="https://www.kaggle.com/abcsds/pokemon")
,tags$hr()
,tags$h1('Image Source')
,tags$hr()
,tags$a("Image Source",href="https://www.pokemon.com/")
,tags$hr())
))))
server <- function(input, output, session) {
observeEvent(input$actionbutton,{
type1u<-as.character(input$firsttype)
healthu<-as.numeric(input$health)
speedu<-as.numeric(input$speed)
nspeedu<-as.numeric(input$nspeed)
ndamageu<-as.numeric(input$ndamage)
spspeedu<-as.numeric(input$circle1)
spdamageu<-as.numeric(input$circle2)
usertotal<-healthu +speedu + nspeedu + ndamageu + spspeedu + spdamageu
high<- usertotal+90
low<- usertotal-40
#newtotal<-round(runif(1,min =low,max =high),0)
checkbetween<- between(data$Total,low,high)
sub1<-subset(data,`Type 1` == type1u & checkbetween == TRUE |`Type 1` == type1u & checkbetween == FALSE )
pokemon<-sample(sub1$Name,1)
output$p<-renderText(pokemon)
output$p2<-renderText(pokemon)
output$max <- renderPrint(high)
output$min<-renderPrint(low)
sub3<-subset(data,Name == pokemon)
linkimage<-sub3$imageurl
output$link<-renderUI(tags$a(href= linkimage,target="_blank","Click here to see your Pokémon"))
output$mytable<-DT::renderDataTable(sub3[,1:13],options = list(
searching = FALSE,
pageLength = 1,
lengthMenu = c(1)))
output$distPlot <- renderPlot({
x <- data$Total
bins <- 25
vlinename<-sub3
vline<-vlinename$Total
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = '#3EB489', border = 'white',xlab="Total Score",main = "")
abline(v=vline,col="black",lty=3)
})
output$distPlo2t <- renderPlot({
graphcombined<-grid.arrange(Barchartcount, Barchartcount2, ncol = 2)
})
output$distplot3 <- renderPlot({
graph1<-plot(wgen)
})
output$distplot4 <- renderPlot({
graph2<-plot(wwlegend)
})
})
#Random button
observeEvent(input$randombutton,{
pokemon<-sample(data$Name,1)
output$p<-renderText(pokemon)
output$p2<-renderText(pokemon)
sub3<-subset(data,Name == pokemon)
linkimage<-sub3$imageurl
output$link<-renderUI(tags$a(href= linkimage,target="_blank","Click here to see your Pokémon"))
output$mytable<-DT::renderDataTable(sub3[,1:13],options = list(
searching = FALSE,
pageLength = 1,
lengthMenu = c(1)))
output$distPlot <- renderPlot({
x <- data$Total
bins <- 25
vlinename<-sub3
vline<-vlinename$Total
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = '#3EB489', border = 'white',xlab="Total Score",main = "")
abline(v=vline,col="black",lty=3)
})
output$distPlo2t <- renderPlot({
graphcombined<-grid.arrange(Barchartcount, Barchartcount2, ncol = 2)
})
output$distplot3 <- renderPlot({
graph1<-plot(wgen)
})
output$distplot4 <- renderPlot({
graph2<-plot(wwlegend)
})
})
}
shinyApp(ui, server)