-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.R
More file actions
194 lines (175 loc) · 5.7 KB
/
script.R
File metadata and controls
194 lines (175 loc) · 5.7 KB
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
library(DT)
library(shiny)
library(readxl)
library(shinydashboard)
library(plotly)
source("dataInput.R")
gen1 <- 1
gen2 <- 1
gen3 <- 1
gen4 <- 1
gen5 <- 1
maxCP <- 3600
minCP <- 10
minDPS <- 10
maxDPS <- 50
lastRevisited <- "2019-09-24"
versionApp <- "v0.3"
ui <- dashboardPage(
skin = "blue",
dashboardHeader(title = div(img(src = ".png", height = 50, width = 50),
paste("Shiny Pokémon Go Dashboard", versionApp)), titleWidth = 600),
dashboardSidebar( width = 200,
sidebarMenu(
menuItem("Dashboard", tabName = "Dashboard", icon = icon("chart-bar")),
menuItem("Info", tabName = "Info", icon = icon("info"))
)
),
dashboardBody(
fluidRow(
tabItems(
#### DASHBOARD ####
tabItem(tabName = "Dashboard",
h1("Pokemon Go"),
column( width = 3,
box(title = "Input Dashboard",
width = NULL,
radioButtons(
inputId = "source",
label = "Calcy IV data source",
choices = c(
"Use the default" = "default",
"Upload your own CalcyIV file" = "file"
)
),
# Wrap the file input in a conditional panel
conditionalPanel(
# The condition should be that the user selects
# "file" from the radio buttons
condition = "input.source == 'file'",
fileInput("calcyIV", "Upload your own CalcyIV csv")
) # end conditional panel
) # end box input
), #end column input
column(width = 9,
box(title = "Overall Details",
width = 9,
valueBoxOutput("maxCP"),
valueBoxOutput("minCP"),
valueBoxOutput("gen1"),
valueBoxOutput("gen2"),
valueBoxOutput("gen3"),
valueBoxOutput("gen4"),
valueBoxOutput("gen5")
) # end value boxes
), # end column value boxes
fluidRow(
box(title = "Graph IV vs CP", width = 5,
plotlyOutput("plot"))),
fluidRow(
box(title = "CP details", width = 10,
DT::dataTableOutput("tableCP"),
sliderInput("cpRange", label = h3("Min and Max CP"),
min = 10, max = 3600, value = c(10, 1499)),
sliderInput("dpsRange", label = h3("Min and Max DPS"),
min = minDPS, max = maxDPS, value = c(minDPS, maxDPS))
) # end box table CP details
) # end fluidRow
), # end tab dashboard
#### INFO ####
tabItem(tabName = "Info",
#### Explanation ####
box(h1("Explanation"),
"blablabla"),
#### Credits ####
box(h1("Credits"),
"Anna Keune"),
box(h1("Changelog"),
"v0.1: using default data and filtering table\n
v0.2: uploading own dataset and tab layout\n
v0.3: improve layout, add plot"
)
) # end tab info
) # end tab items
)
)
)
server <- function(input, output) {
dataCalcy <- reactive({
if (input$source == "default") {
data <- read.csv("history_20190929_084646.csv")
} else if (input$source == "file") {
data <- inputFile()
}
return(data)
})
inputFile <- reactive({
inFile <- input$calcyIV
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath)
return(df)
})
mergedData <- reactive({
pokemonStats <- read_excel("PokemonStats.xlsx", sheet = 3)
dataPokemon <- dataCalcy()
dataPokemon$Nat <- dataPokemon$Nr
allDetails <- merge(dataPokemon, pokemonStats, by = "Nat")
allDetails <- AddGeneration(allDetails)
return(allDetails)
})
output$tableCP <- DT::renderDataTable({
df <- mergedData()
filteredData <- df[df$CP >= input$cpRange[1] & df$CP <= input$cpRange[2], ]
displayData <- filteredData[ , c("Nr", "Name", "CP", "DPS", "Fast.move", "Special.move", "max.IV.", "Type I", "Type II")]
DT::datatable(displayData)
})
output$plot <- renderPlotly({
df <- mergedData()
plot_ly(df, x = ~CP, y = ~max.IV.)
})
generationCount <- reactive({CountGeneration(mergedData())})
output$gen1 <- renderValueBox(
valueBox(value = generationCount()$gen1,
subtitle = "Gen 1",
icon = icon("dot-circle"),
color = "blue")
)
output$gen2 <- renderValueBox(
valueBox(value = generationCount()$gen2,
subtitle = "Gen 2",
icon = icon("dot-circle"),
color = "blue")
)
output$gen3 <- renderValueBox(
valueBox(value = generationCount()$gen3,
subtitle = "Gen 3",
icon = icon("dot-circle"),
color = "blue")
)
output$gen4 <- renderValueBox(
valueBox(value = generationCount()$gen4,
subtitle = "Gen 4",
icon = icon("dot-circle"),
color = "blue")
)
output$gen5 <- renderValueBox(
valueBox(value = generationCount()$gen5,
subtitle = "Gen 5",
icon = icon("dot-circle"),
color = "blue")
)
output$maxCP <- renderValueBox(
valueBox(value = max(mergedData()$CP),
subtitle = "Max CP",
icon = icon("grin-stars"),
color = "red")
)
output$minCP <- renderValueBox(
valueBox(value = min(mergedData()$CP),
subtitle = "Min CP",
icon = icon("meh"),
color = "red")
)
}
shinyApp(ui = ui, server = server)