Skip to content

Commit 240895b

Browse files
committed
20260309 - MM upload app
1 parent 4e06577 commit 240895b

237 files changed

Lines changed: 113522 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app.R

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
#
2+
# This is a Shiny web application. You can run the application by clicking
3+
# the 'Run App' button above.
4+
#
5+
# Find out more about building applications with Shiny here:
6+
#
7+
# https://shiny.posit.co/
8+
#
9+
10+
library(shiny)
11+
library(shinyWidgets)
12+
library(shinylive)
13+
library(httpuv)
14+
15+
# Define UI for application that calculates time
16+
ui <- fluidPage(
17+
18+
# Application title
19+
titlePanel("Task Timing Calculator"),
20+
21+
br(),
22+
23+
mainPanel(
24+
25+
fluidRow(
26+
column(4, numericInput("time1_h", "Task Start Time (HH)", 0, min = 0)),
27+
column(4, numericInput("time1_m", "Task Start Time (MM)", 0, min = 0, max = 59)),
28+
column(4, numericInput("time1_s", "Task Start Time (SS)", 0, min = 0, max = 59))
29+
),
30+
br(),
31+
32+
fluidRow(
33+
column(4, numericInput("time2_h", "Task End Time (HH)", 0, min = 0)),
34+
column(4, numericInput("time2_m", "Task End Time (MM)", 0, min = 0, max = 59)),
35+
column(4, numericInput("time2_s", "Task End Time (SS)", 0, min = 0, max = 59))
36+
37+
38+
)),
39+
br(),
40+
41+
sidebarPanel(
42+
checkboxInput("interruption", "Was there an interruption?", value = FALSE),
43+
conditionalPanel(condition = "input.interruption == true",
44+
45+
numericInput("num_int", "Number of Interruptions", value = 0, min = 0, max = 10, step = 1),
46+
47+
uiOutput("interruptions_ui"),
48+
49+
),
50+
51+
width= 8),
52+
53+
br(),
54+
55+
actionButton("reset", "Reset"),
56+
57+
hr(),
58+
59+
h3("Total Coded Time"),
60+
span(textOutput ("coded_time"), style= "font-size:20px")
61+
62+
63+
64+
)
65+
66+
67+
# Server to calculate time
68+
server <- function(input, output, session) {
69+
70+
coded_time <- reactive({
71+
72+
start_sec <- input$time1_h*3600 + input$time1_m*60 + input$time1_s
73+
74+
end_sec <- input$time2_h*3600 + input$time2_m*60 + input$time2_s
75+
76+
total_time <- end_sec - start_sec
77+
78+
79+
# Interruptions
80+
n <- input$num_int %||% 0
81+
82+
if (n > 0) {
83+
84+
interruption_seconds <- 0
85+
86+
for (i in 1:n) {
87+
88+
start_h <- input[[paste0("int", i, "_start_h")]]
89+
start_m <- input[[paste0("int", i, "_start_m")]]
90+
start_s <- input[[paste0("int", i, "_start_s")]]
91+
92+
end_h <- input[[paste0("int", i, "_end_h")]]
93+
end_m <- input[[paste0("int", i, "_end_m")]]
94+
end_s <- input[[paste0("int", i, "_end_s")]]
95+
96+
int_start <- start_h*3600 + start_m*60 + start_s
97+
int_end <- end_h*3600 + end_m*60 + end_s
98+
99+
interruption_seconds <- interruption_seconds + (int_end - int_start)
100+
}
101+
102+
total_time <- total_time - interruption_seconds
103+
}
104+
105+
max(total_time, 0)
106+
107+
})
108+
109+
output$interruptions_ui <- renderUI({
110+
111+
n <- min(input$num_int %||% 0, 10)
112+
113+
if (is.null(n) || n == 0) return(NULL)
114+
115+
lapply(1:n, function(i) {
116+
117+
tagList(
118+
119+
h4(paste("Interruption", i)),
120+
121+
fluidRow(
122+
column(4, numericInput(paste0("int", i, "_start_h"),
123+
"Start Time (HH)", 0, min = 0)),
124+
column(4, numericInput(paste0("int", i, "_start_m"),
125+
"Start Time (MM)", 0, min = 0, max = 59)),
126+
column(4, numericInput(paste0("int", i, "_start_s"),
127+
"Start Time (SS)", 0, min = 0, max = 59))
128+
),
129+
130+
br(),
131+
132+
fluidRow(
133+
column(4, numericInput(paste0("int", i, "_end_h"),
134+
"End Time (HH)", 0, min = 0)),
135+
column(4, numericInput(paste0("int", i, "_end_m"),
136+
"End Time (MM)", 0, min = 0, max = 59)),
137+
column(4, numericInput(paste0("int", i, "_end_s"),
138+
"End Time (SS)", 0, min = 0, max = 59))
139+
),
140+
141+
br()
142+
)
143+
})
144+
145+
})
146+
147+
output$coded_time <- renderText({
148+
149+
seconds <- coded_time()
150+
151+
h <- seconds %/% 3600
152+
m <- (seconds %% 3600) %/% 60
153+
s <- seconds %% 60
154+
155+
sprintf("%02d:%02d:%02d", h, m, s)
156+
157+
})
158+
159+
observeEvent(input$reset, {
160+
161+
updateNumericInput(session, "time1_h", value= 0)
162+
updateNumericInput(session, "time1_m", value= 0)
163+
updateNumericInput(session, "time1_s", value= 0)
164+
165+
updateNumericInput(session, "time2_h", value= 0)
166+
updateNumericInput(session, "time2_m", value= 0)
167+
updateNumericInput(session, "time2_s", value= 0)
168+
169+
updateCheckboxInput(session, "interruption", value = FALSE)
170+
updateNumericInput(session, "num_int", value= 0)
171+
})
172+
}
173+
174+
175+
# Run the application
176+
shinyApp(ui = ui, server = server)
177+
178+
#Use the lines below to export app changes
179+
180+
#shinylive::export("V:/mametz/GitHub/timing_calculator", "V:/mametz/GitHub/timing_calculator/docs")
181+
#httpuv::runStaticServer("docs/", port = 8008)

docs/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"name":"app.R","content":"#\r\n# This is a Shiny web application. You can run the application by clicking\r\n# the 'Run App' button above.\r\n#\r\n# Find out more about building applications with Shiny here:\r\n#\r\n# https://shiny.posit.co/\r\n#\r\n\r\nlibrary(shiny)\r\nlibrary(shinyWidgets)\r\nlibrary(shinylive)\r\nlibrary(httpuv)\r\n\r\n# Define UI for application that calculates time\r\nui <- fluidPage(\r\n\r\n # Application title\r\n titlePanel(\"Task Timing Calculator\"),\r\n\r\n br(),\r\n\r\n mainPanel(\r\n \r\n fluidRow(\r\n column(4, numericInput(\"time1_h\", \"Task Start Time (HH)\", 0, min = 0)),\r\n column(4, numericInput(\"time1_m\", \"Task Start Time (MM)\", 0, min = 0, max = 59)),\r\n column(4, numericInput(\"time1_s\", \"Task Start Time (SS)\", 0, min = 0, max = 59))\r\n ),\r\n br(),\r\n \r\n fluidRow(\r\n column(4, numericInput(\"time2_h\", \"Task End Time (HH)\", 0, min = 0)),\r\n column(4, numericInput(\"time2_m\", \"Task End Time (MM)\", 0, min = 0, max = 59)),\r\n column(4, numericInput(\"time2_s\", \"Task End Time (SS)\", 0, min = 0, max = 59))\r\n\r\n \r\n )),\r\n br(),\r\n \r\n sidebarPanel(\r\n checkboxInput(\"interruption\", \"Was there an interruption?\", value = FALSE),\r\n conditionalPanel(condition = \"input.interruption == true\",\r\n \r\n numericInput(\"num_int\", \"Number of Interruptions\", value = 0, min = 0, max = 10, step = 1),\r\n \r\n uiOutput(\"interruptions_ui\"),\r\n \r\n ),\r\n \r\n width= 8),\r\n \r\n br(),\r\n \r\n actionButton(\"reset\", \"Reset\"),\r\n \r\n hr(),\r\n \r\n h3(\"Total Coded Time\"),\r\n span(textOutput (\"coded_time\"), style= \"font-size:20px\")\r\n\r\n\r\n\r\n)\r\n \r\n\r\n# Server to calculate time\r\nserver <- function(input, output, session) {\r\n \r\n coded_time <- reactive({\r\n \r\n start_sec <- input$time1_h*3600 + input$time1_m*60 + input$time1_s\r\n \r\n end_sec <- input$time2_h*3600 + input$time2_m*60 + input$time2_s\r\n \r\n total_time <- end_sec - start_sec\r\n \r\n \r\n # Interruptions\r\n n <- input$num_int %||% 0\r\n \r\n if (n > 0) {\r\n \r\n interruption_seconds <- 0\r\n \r\n for (i in 1:n) {\r\n \r\n start_h <- input[[paste0(\"int\", i, \"_start_h\")]]\r\n start_m <- input[[paste0(\"int\", i, \"_start_m\")]]\r\n start_s <- input[[paste0(\"int\", i, \"_start_s\")]]\r\n \r\n end_h <- input[[paste0(\"int\", i, \"_end_h\")]]\r\n end_m <- input[[paste0(\"int\", i, \"_end_m\")]]\r\n end_s <- input[[paste0(\"int\", i, \"_end_s\")]]\r\n \r\n int_start <- start_h*3600 + start_m*60 + start_s\r\n int_end <- end_h*3600 + end_m*60 + end_s\r\n \r\n interruption_seconds <- interruption_seconds + (int_end - int_start)\r\n }\r\n \r\n total_time <- total_time - interruption_seconds\r\n }\r\n \r\n max(total_time, 0)\r\n \r\n })\r\n \r\n output$interruptions_ui <- renderUI({\r\n \r\n n <- min(input$num_int %||% 0, 10)\r\n \r\n if (is.null(n) || n == 0) return(NULL)\r\n \r\n lapply(1:n, function(i) {\r\n \r\n tagList(\r\n \r\n h4(paste(\"Interruption\", i)),\r\n \r\n fluidRow(\r\n column(4, numericInput(paste0(\"int\", i, \"_start_h\"),\r\n \"Start Time (HH)\", 0, min = 0)),\r\n column(4, numericInput(paste0(\"int\", i, \"_start_m\"),\r\n \"Start Time (MM)\", 0, min = 0, max = 59)),\r\n column(4, numericInput(paste0(\"int\", i, \"_start_s\"),\r\n \"Start Time (SS)\", 0, min = 0, max = 59))\r\n ),\r\n \r\n br(),\r\n \r\n fluidRow(\r\n column(4, numericInput(paste0(\"int\", i, \"_end_h\"),\r\n \"End Time (HH)\", 0, min = 0)),\r\n column(4, numericInput(paste0(\"int\", i, \"_end_m\"),\r\n \"End Time (MM)\", 0, min = 0, max = 59)),\r\n column(4, numericInput(paste0(\"int\", i, \"_end_s\"),\r\n \"End Time (SS)\", 0, min = 0, max = 59))\r\n ),\r\n \r\n br()\r\n )\r\n })\r\n \r\n })\r\n\r\noutput$coded_time <- renderText({\r\n \r\n seconds <- coded_time()\r\n \r\n h <- seconds %/% 3600\r\n m <- (seconds %% 3600) %/% 60\r\n s <- seconds %% 60\r\n \r\n sprintf(\"%02d:%02d:%02d\", h, m, s)\r\n\r\n})\r\n\r\nobserveEvent(input$reset, {\r\n \r\n updateNumericInput(session, \"time1_h\", value= 0)\r\n updateNumericInput(session, \"time1_m\", value= 0)\r\n updateNumericInput(session, \"time1_s\", value= 0)\r\n \r\n updateNumericInput(session, \"time2_h\", value= 0)\r\n updateNumericInput(session, \"time2_m\", value= 0)\r\n updateNumericInput(session, \"time2_s\", value= 0)\r\n \r\n updateCheckboxInput(session, \"interruption\", value = FALSE)\r\n updateNumericInput(session, \"num_int\", value= 0)\r\n})\r\n}\r\n\r\n\r\n# Run the application \r\nshinyApp(ui = ui, server = server)\r\n\r\n\r\n#shinylive::export(\"C:/Users/mametz/Documents/R Stuff/TimingCalculator\", \"docs\")\r\n#shinylive::export(\"C:/Users/mametz/Documents/R Stuff/TimingCalculator\", \"V:/mametz/GitHub/timing_calculator/docs\")\r\n#httpuv::runStaticServer(\"docs/\", port = 8008)\r\n","type":"text"},{"name":"README.md","content":"# timing_calculator","type":"text"}]

docs/edit/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3+
<head>
4+
<title>Redirect to editable app</title>
5+
<meta
6+
http-equiv="refresh"
7+
content="0;URL='../index.html?_shinylive-mode=editor-terminal-viewer'"
8+
/>
9+
</head>
10+
<body></body>
11+
</html>

docs/index.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Shiny App</title>
7+
<script
8+
src="./shinylive/load-shinylive-sw.js"
9+
type="module"
10+
></script>
11+
<script type="module">
12+
import { runExportedApp } from "./shinylive/shinylive.js";
13+
runExportedApp({
14+
id: "root",
15+
appEngine: "r",
16+
relPath: "",
17+
});
18+
</script>
19+
<link rel="stylesheet" href="./shinylive/style-resets.css" />
20+
<link rel="stylesheet" href="./shinylive/shinylive.css" />
21+
22+
</head>
23+
<body>
24+
25+
<div style="height: 100vh; width: 100vw" id="root"></div>
26+
27+
</body>
28+
</html>

0 commit comments

Comments
 (0)