-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
181 lines (118 loc) · 4.85 KB
/
app.R
File metadata and controls
181 lines (118 loc) · 4.85 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
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# https://shiny.posit.co/
#
library(shiny)
library(shinyWidgets)
library(shinylive)
library(httpuv)
# Define UI for application that calculates time
ui <- fluidPage(
# Application title
titlePanel("Task Timing Calculator"),
br(),
mainPanel(
fluidRow(
column(4, numericInput("time1_h", "Task Start Time (HH)", 0, min = 0)),
column(4, numericInput("time1_m", "Task Start Time (MM)", 0, min = 0, max = 59)),
column(4, numericInput("time1_s", "Task Start Time (SS)", 0, min = 0, max = 59))
),
br(),
fluidRow(
column(4, numericInput("time2_h", "Task End Time (HH)", 0, min = 0)),
column(4, numericInput("time2_m", "Task End Time (MM)", 0, min = 0, max = 59)),
column(4, numericInput("time2_s", "Task End Time (SS)", 0, min = 0, max = 59))
)),
br(),
sidebarPanel(
checkboxInput("interruption", "Was there an interruption?", value = FALSE),
conditionalPanel(condition = "input.interruption == true",
numericInput("num_int", "Number of Interruptions", value = 0, min = 0, max = 10, step = 1),
uiOutput("interruptions_ui"),
),
width= 8),
br(),
actionButton("reset", "Reset"),
hr(),
h3("Total Coded Time"),
span(textOutput ("coded_time"), style= "font-size:20px")
)
# Server to calculate time
server <- function(input, output, session) {
coded_time <- reactive({
start_sec <- input$time1_h*3600 + input$time1_m*60 + input$time1_s
end_sec <- input$time2_h*3600 + input$time2_m*60 + input$time2_s
total_time <- end_sec - start_sec
# Interruptions
n <- input$num_int %||% 0
if (n > 0) {
interruption_seconds <- 0
for (i in 1:n) {
start_h <- input[[paste0("int", i, "_start_h")]]
start_m <- input[[paste0("int", i, "_start_m")]]
start_s <- input[[paste0("int", i, "_start_s")]]
end_h <- input[[paste0("int", i, "_end_h")]]
end_m <- input[[paste0("int", i, "_end_m")]]
end_s <- input[[paste0("int", i, "_end_s")]]
int_start <- start_h*3600 + start_m*60 + start_s
int_end <- end_h*3600 + end_m*60 + end_s
interruption_seconds <- interruption_seconds + (int_end - int_start)
}
total_time <- total_time - interruption_seconds
}
max(total_time, 0)
})
output$interruptions_ui <- renderUI({
n <- min(input$num_int %||% 0, 10)
if (is.null(n) || n == 0) return(NULL)
lapply(1:n, function(i) {
tagList(
h4(paste("Interruption", i)),
fluidRow(
column(4, numericInput(paste0("int", i, "_start_h"),
"Start Time (HH)", 0, min = 0)),
column(4, numericInput(paste0("int", i, "_start_m"),
"Start Time (MM)", 0, min = 0, max = 59)),
column(4, numericInput(paste0("int", i, "_start_s"),
"Start Time (SS)", 0, min = 0, max = 59))
),
br(),
fluidRow(
column(4, numericInput(paste0("int", i, "_end_h"),
"End Time (HH)", 0, min = 0)),
column(4, numericInput(paste0("int", i, "_end_m"),
"End Time (MM)", 0, min = 0, max = 59)),
column(4, numericInput(paste0("int", i, "_end_s"),
"End Time (SS)", 0, min = 0, max = 59))
),
br()
)
})
})
output$coded_time <- renderText({
seconds <- coded_time()
h <- seconds %/% 3600
m <- (seconds %% 3600) %/% 60
s <- seconds %% 60
sprintf("%02d:%02d:%02d", h, m, s)
})
observeEvent(input$reset, {
updateNumericInput(session, "time1_h", value= 0)
updateNumericInput(session, "time1_m", value= 0)
updateNumericInput(session, "time1_s", value= 0)
updateNumericInput(session, "time2_h", value= 0)
updateNumericInput(session, "time2_m", value= 0)
updateNumericInput(session, "time2_s", value= 0)
updateCheckboxInput(session, "interruption", value = FALSE)
updateNumericInput(session, "num_int", value= 0)
})
}
# Run the application
shinyApp(ui = ui, server = server)
#Use the lines below to export app changes
#shinylive::export("V:/mametz/GitHub/timing_calculator", "V:/mametz/GitHub/timing_calculator/docs")
#httpuv::runStaticServer("docs/", port = 8008)