...
 
Commits (3)
testing
rsconnect::setAccountInfo(name="rh-uxd", token="D01B3EDE3E652F4AF4A8E86B1437F00B", secret="9fUijGOJhhcqTfgVz7b3QJS6htBs83Cmd/En6Hcn")
setwd("/Users/cjpearson/Documents/school/r_github/Time-converter/time-converter")
rsconnect::deployApp()
library(tidyverse)
......@@ -50,3 +55,7 @@ time.vector2 <- sapply(time.v, function(x) {
}
)
time.duration2 <- lubridate::duration(hours=time.vector2[1],minutes=time.vector2[2],seconds=time.vector2[3])
......@@ -7,126 +7,130 @@
# http://shiny.rstudio.com/
#
library(shiny)
library(lubridate)
source("Helpers.R")
# Define UI for application that draws a histogram
# Define UI for application
ui <- fluidPage(
# Application title
titlePanel("Timestamp Calculator"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
h4("Enter Timestamp 1"),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="h1",
"Hours",
value=00,
min = 00,
max = 24,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="m1",
"Minutes",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="s1",
"Seconds",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
hr(),
h4("Enter Timestamp 2"),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="h2",
"Hours",
value=00,
min = 00,
max = 24,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="m2",
"Minutes",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="s2",
"Seconds",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
hr(),
actionButton("do", "Calculate Duration")
),
# Show a plot of the generated distribution
mainPanel(
htmlOutput("dur")
)
)
# Application title with link to gitlab
titlePanel(
tags$a(href="https://gitlab.com/carljpearson/time-converter/tree/master", "Timestamp Calculator"),hr()
),
# time entry for timestamps
fluidRow(
column(4, offset = 3,
h4("Enter Timestamp 1:"),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="h1",
"Hours",
value=00,
min = 00,
max = 24,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="m1",
"Minutes",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="s1",
"Seconds",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
hr(),
h4("Enter Timestamp 2:"),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="h2",
"Hours",
value=00,
min = 00,
max = 24,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="m2",
"Minutes",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
div(style="display: inline-block;vertical-align:top; width: 60px;",
numericInput(inputId="s2",
"Seconds",
value=00,
min = 00,
max = 60,
step = 1,
width = NULL)
),
hr(),
#action button to calculate duration
actionButton("do", "Calculate Duration"),
hr(),
# Show a plot of the generated distribution
#output div
div(style="font-size:25px;background-color:WhiteSmoke;padding:8px;border-radiux;8px;",
htmlOutput("dur")
)
)
)
)
# Define server to calculate seconds from min
server <- function(input, output) {
#function to calculate output or error
duration <- eventReactive(input$do,{
time1 <- time.ify(input$h1,input$m1,input$s1)
time2 <- time.ify(input$h2,input$m2,input$s2)
#if (time2 > time1){
final <- time2-time1
# } else if (time1==time2) {
# final <- "err2"
#} else {
# final <- "err1"
# }
if (time2 > time1){ #for correct input, give output verbage with duration value
final <- time2-time1
HTML(paste("This time segment's duration is:",final,sep = '<br/>')) -> out
} else if (time1==time2) { #if values are equal, give error
"Please enter two different timestamps above." -> out
} else if (time2 < time1) { #if time would be negative, give error
"Error: Timestamp 1 needs to be earlier than Timestamp 2." -> out
}
out
})
#function renders output html
output$dur <- renderUI({
final
duration()
})
output$dur <- renderUI({
#if (duration()=="err1") {
# "Error: Timestamp 1 needs to be earlier than Timestamp 2."
# } else if (duration()=="err2") {
# "Please enter two different timestamps in the gray panel."
#} else {
HTML(paste("This time segment's duration is:",duration(),sep = '<br/>'))
# }
})
}
# Run the application
......