-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappLogic.R
74 lines (67 loc) · 2.35 KB
/
appLogic.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
# application specific logic
# last update: 2017-02-13
source('srvDateselect.R', local=TRUE)
source('srvEmail.R', local=TRUE)
source('srvScheduler.R', local=TRUE)
# any record manipulations before storing a record
appData <- function(record){
record
}
getRepoStruct <- function(repo){
appStruct[[repo]]
}
repoData <- function(repo){
data <- data.frame()
app <- currApp()
if(length(app) > 0){
url <- itemsUrl(app[['url']],
repo)
data <- readItems(app, url)
}
data
}
# anything that should run only once during startup
appStart <- function(){
data <- currData()
babies <- unique(data$name)
babies[is.na(babies)] <- '<leer>'
updateSelectInput(session, 'babySelect',
choices = c('alle', babies))
gonimoSetup <- paste0(
"localStorage.setItem('OYD', JSON.stringify({piaURL:'",
piaUrl,
"', appSecret:'",
appSecret,
"', interval:5000",
", threshold:0.3",
"}));")
session$sendCustomMessage(type='setGonimoSetup', gonimoSetup)
}
output$gonimoChart <- renderPlotly({
data <- currDataDateSelectTimestamp()
pdf(NULL)
outputPlot <- plotly_empty()
if(nrow(data) > 0){
data$dat <- as.Date(as.POSIXct(data$time/1000, origin = '1970-01-01'))
data$date <- as.POSIXct(data$time/1000, origin = '1970-01-01')
data$val <- as.numeric(data$volume)
data$color <- 'blue'
data[data$val > 0.4, 'color'] <- 'orange'
outputPlot <- plot_ly(
data,
x = ~data$date,
y = ~data$val,
type = 'bar',
marker = list(color = data$color)
) %>% layout( title = '',
showlegend = FALSE,
margin = list(l = 80, r = 80),
yaxis = list(title = 'Lautstärke'),
xaxis = list(
title = '',
rangeslider = list(type = 'date'))
)
}
dev.off()
outputPlot
})