-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.R
47 lines (39 loc) · 1.2 KB
/
server.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
library(StreamMetabolism)
library(lubridate)
get.sunrise <- function(lat, lon, date, n){
tmp <- sunrise.set(lat, lon, date, timezone="UTC", num.days = n)
solar <- tmp
solar$sunrise <- POSIXctToHour(tmp[,1]) #hour(tmp[,1]) + minute(tmp[,1]) / 60 + second(tmp[,1]) / 3600
solar$sunset <- POSIXctToHour(tmp[,2])
return (solar)
}
POSIXctToHour <- function(POSIXct){
hour <- hour(POSIXct) + minute(POSIXct) / 60 + second(POSIXct) / 3600
return (hour)
}
defaultNumeric <- function(input){
if(is.null(input)){
output=0
}else{
if (input == "") {
output=0
}else{
if (is.numeric(input) == FALSE) {
output=0
}
}
}
return (output)
}
shinyServer(function(input, output, clientData) {
output$nText2 <- renderPlot({
lat <- input$lat
lon <- input$lon
time <- get.sunrise(lat, lon, input$date,input$n)
plot(time$sunrise , ylab='Time UTC',xlab='Days', col='red',main='Solar Events', ylim=c(0,24))
par(new=T)
plot(time$sunset, ylab='Time UTC',xlab='Days', col='Midnight Blue',main='Solar Events', ylim=c(0,24))
par(new=F)
legend('topright', pch=c(19,19),col=c('Midnight Blue','red'),legend=c('Sunset','Sunrise'))
})
})