-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.R
95 lines (84 loc) · 3.54 KB
/
app.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
library(shiny)
library(shinydashboard)
library(data.table)
library(DT)
orc_ratings = setDT(read.table("orc_ratings.csv", header = TRUE, sep = ",", check.names = FALSE))
ui = fluidPage(
titlePanel("ORC Ratings"),
fluidRow(
column(2,
selectInput("yacht",
h4("Yacht Name"),
orc_ratings$Yacht, selected = "Kuai")
),
column(2,
numericInput("time", label = h4("Time On Course"), value = 60)
),
column(8,
checkboxGroupInput("course", label = h4("Course Types"),
choices = names(orc_ratings)[-1],
inline = TRUE,
selected = names(orc_ratings)[2])
)
),
# Create a new row for the table.
fluidRow(
tabBox(width = 12,
tabPanel('Time Owed', DT::dataTableOutput("owed")),
tabPanel('ORC Ratings', DT::dataTableOutput("ratings"))
)
)
)
server = function(input, output) {
owed_times = reactive({
req(input$course)
owed_times_dt = data.table()
lapply(input$course, function(x) {
data <- setnames(orc_ratings[,c('Yacht', ..x)], c("Yacht Name","rating"))
boat_rating = data[data$Yacht == input$yacht, rating]
data = data[order(-rating)]
data[, Course := x]
data[, `After Time On Course` := (boat_rating / rating * input$time) - input$time]
data[, `After 60 min` := (boat_rating / rating * 60) - 60]
data[, rating := NULL]
if (length(owed_times_dt) == 0) {
owed_times_dt <<- data
}
else
{
owed_times_dt <<- rbind(owed_times_dt, data)
}
})
owed_times_dt$`After 90 min` = owed_times_dt$`After 60 min` * 1.5
owed_times_dt$`After 120 min` = owed_times_dt$`After 60 min` * 2
owed_times_dt$`After Time On Course` = paste0(owed_times_dt$`After Time On Course` -(owed_times_dt$`After Time On Course`%%sign(owed_times_dt$`After Time On Course`)) ," min ", round(owed_times_dt$`After Time On Course`%%sign(owed_times_dt$`After Time On Course`)*60,0), " sec")
owed_times_dt$`After 60 min` = paste0(owed_times_dt$`After 60 min` -(owed_times_dt$`After 60 min`%%sign(owed_times_dt$`After 60 min`)) ," min ", round(owed_times_dt$`After 60 min`%%sign(owed_times_dt$`After 60 min`)*60,0), " sec")
owed_times_dt$`After 90 min` = paste0(owed_times_dt$`After 90 min` -(owed_times_dt$`After 90 min`%%sign(owed_times_dt$`After 90 min`)) ," min ", round(owed_times_dt$`After 90 min`%%sign(owed_times_dt$`After 90 min`)*60,0), " sec")
owed_times_dt$`After 120 min` = paste0(owed_times_dt$`After 120 min` -(owed_times_dt$`After 120 min`%%sign(owed_times_dt$`After 120 min`)) ," min ", round(owed_times_dt$`After 120 min`%%sign(owed_times_dt$`After 120 min`)*60,0), " sec")
owed_times_dt[`Yacht Name`== input$yacht, names(owed_times_dt)[c(-1,-2)] := "--------------" ]
owed_times_dt
}
)
output$owed <- DT::renderDataTable(DT::datatable(
data = owed_times(),
extensions = c('FixedHeader', 'Buttons', 'ColReorder', 'Scroller'),
rownames= FALSE,
options = list(
dom = 'Bfrti',
searching = FALSE,
pageLength = nrow(owed_times()),
buttons = c('copy', 'print')
)))
output$ratings <- DT::renderDataTable(DT::datatable(
data = orc_ratings,
extensions = c('FixedHeader', 'Buttons', 'ColReorder', 'Scroller'),
rownames= FALSE,
options = list(
dom = 'Bfrti',
searching = FALSE,
pageLength = nrow(orc_ratings),
buttons = c('copy', 'csv', 'print')
)
))
}
shinyApp(server = server, ui = ui)