Commit 0e8e3143 authored by jlopez's avatar jlopez
Browse files

Add shiny app

parent df83be7a
......@@ -38,14 +38,17 @@ mandrill_uuid <- c("32-38-31-39-58-36-8e-0c")
# Temperature mandrill
#--------------------------------------------------
path_temperature <- paste0(root_path, "/logLoRaTemp.csv")
preTraitementTemperature(root_path, path_temperature, mandrill_uuid, timeS, timeE)
mandrill_temperature <- readCSVTemperature(paste0(root_path, "/temperature.csv"))
#if you don't have extern temp
#extTemperature <- data.frame(date=as.character(), uuid=as.character(), temperature=as.numeric())
extTemperature <- extractExtTemperature(paste0(root_path, "/temperature_ext.xlsx"), timeS, timeE)
pathTemperature <- paste0(root_path, "/temperature_ext.xlsx")
if(file.exists(pathTemperature)) {
extTemperature <- data.frame(date=as.character(), uuid=as.character(), temperature=as.numeric())
} else {
extTemperature <- extractExtTemperature(pathTemperature, timeS, timeE)
}
minT <- min(mandrill_temperature$temperature, extTemperature$temperature)
......@@ -74,7 +77,7 @@ if(length(uuid) > 1) {
#legend("topleft", legend = uuid, col = color_mandrill, lty = 1, cex = 0.8)
#lines(extTemperature$date,extTemperature$temperature, col="red")
lines(extTemperature$date,extTemperature$temperature, col="red")
#abline(h=mean(mandrill_temperature$temperature), col="blue")
#abline(h=mean(extTemperature$temperature), col="red")
......
"uuid"
"32-38-31-39-62-36-8f-0c"
"32-38-31-39-65-36-88-0c"
"32-38-31-39-66-36-6d-0c"
"32-38-31-39-66-36-82-0c"
"32-38-31-39-62-36-86-0c"
"32-38-31-39-61-36-74-0c"
"32-38-31-39-61-36-77-0c"
"32-38-31-39-5a-36-74-0c"
"32-38-31-39-66-36-73-0c"
"32-38-31-39-65-36-84-0c"
"32-38-31-39-57-36-8d-0c"
"32-38-31-39-62-36-92-0c"
"32-38-31-39-57-36-74-0c"
"32-38-31-39-67-36-63-0c"
"32-38-31-39-66-36-63-0c"
"32-38-31-39-66-36-7e-0c"
"32-38-31-39-62-36-87-0c"
"32-38-31-39-61-36-93-0c"
"32-38-31-39-61-36-6c-0c"
"32-38-31-39-66-36-6a-0c"
"32-38-31-39-62-36-8a-0c"
"32-38-31-39-61-36-6a-0c"
"32-38-31-39-62-36-73-0c"
"32-38-31-39-62-36-7e-0c"
"32-38-31-39-67-36-61-0c"
"32-38-31-39-66-36-74-0c"
"32-38-31-39-60-36-81-0c"
"32-38-31-39-62-36-90-0c"
"32-38-31-39-66-36-6e-0c"
"32-38-31-39-66-36-67-0c"
"32-38-31-39-57-36-88-0c"
"32-38-31-39-66-36-7a-0c"
"32-38-31-39-66-36-68-0c"
"32-38-31-39-62-36-77-0c"
"32-38-31-39-5e-36-8d-0c"
"32-38-31-39-62-36-7d-0c"
"32-38-31-39-66-36-75-0c"
"32-38-31-39-61-36-7c-0c"
"32-38-31-39-62-36-88-0c"
"32-38-31-39-62-36-82-0c"
"32-38-31-39-66-36-7b-0c"
"32-38-31-39-58-36-8e-0c"
"32-38-31-39-61-36-91-0c"
"32-38-31-39-62-36-89-0c"
MenuGauche = sidebarMenu(id = "sidebarmenu",
menuItem("Home", tabName = "Home", icon = icon("home", lib="font-awesome")),
selectInput("pathMandrill", "Week:",
PATHWEEK),
selectInput("uuidMandrill", "Mandrill:", multiple = FALSE, selected = "32-38-31-39-58-36-8e-0c",
UUIDMANDRILL),
checkboxGroupInput("checkGroupParam", label = "Diagramme :",
choices = list("Temperature" = 1, "Acceleration X" = 2, "Acceleration Y" = 3, "Acceleration Z" = 4),
selected = c(1,2,3,4)),
actionButton("runButton", "Run"),
tags$br(), tags$br(), tags$br(),
menuItem("Team", icon = icon("book", lib="font-awesome"),
menuItem("Jimmy Lopez", href = "http://www.isem.univ-montp2.fr/recherche/les-plate-formes/bioinformatique-labex/personnel/", newtab = TRUE, icon = shiny::icon("male"), selected = NULL )
)
)
library(shiny)
library(shinydashboard)
library(shinyjs)
library(DT)
library(dplyr)
library(devtools)
library(shinyFiles)
library(dplyr)
library(broman)
library(randomcoloR)
library(openxlsx)
library(Rcpp)
source("../tools.R")
sourceCpp("../exstract.cpp")
root <- "/home/jimmy/jimmy/projets/mandrill/data"
data <- list.dirs(root)
data <- data[2:length(data)]
names(data) <- basename(data)
PATHWEEK <<- data
UUIDMANDRILL <- read.csv("../mandrill.csv")
source("./R/helper_functions.R", local = T)
source("./R/menugauche.R", local = T)
source("./pages/pages_def_home.R", local = T)
options(encoding = 'UTF-8')
options(shiny.maxRequestSize=200*1024^2)
style <- tags$style(HTML(readLines("www/added_styles.css")) )
UI <- dashboardPage(
skin = "blue",
dashboardHeader(title = "Mandrill"),
dashboardSidebar(MenuGauche),
dashboardBody(
shinyjs::useShinyjs(),
tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.min.readable.css")) ,
tags$head(style),
tags$head(tags$script(src = "message-handler.js")),
tabItems(
tabItem(tabName = "Home", tabHome)
)
)
)
server <- function( input, output, session) {
source("./server/opt_home.R", local=T)
}
shinyApp(ui = UI, server = server)
tabHome = fluidPage(align="left",
column(width = 12,
includeHTML("./www/spinner.html"),
sliderInput("slider_datetime", "Date & Time:", width = "100%",
min=as.POSIXlt("2018-01-01 00:00:00", "GMT"),
max=as.POSIXlt("2019-06-06 23:59:59", "GMT"),
value=c(as.POSIXlt("2018-11-26 12:00:00", "GMT"), as.POSIXlt("2018-11-27 11:59:59", "GMT")),
timezone = "GMT"),
br(),
plotOutput("temperature", height = "600px"),
plotOutput("accX", height = "800px"),
plotOutput("accY", height = "800px"),
plotOutput("accZ", height = "800px")
)
)
\ No newline at end of file
observeEvent(input$pathMandrill, {
start <- as.POSIXlt(paste0(basename(input$pathMandrill), " 00:00:00"), "GMT")
secondDays <- 60*60*24
end <- start + secondDays*8-1
selectStart <- as.POSIXlt(paste0(basename(input$pathMandrill), " 12:00:00"), "GMT")
selectEnd <- selectStart + secondDays - 1
updateSliderInput(session, "slider_datetime", value = c(selectStart, selectEnd),
min = start, max = end)
})
observeEvent(input$runButton, {
typeD <- isolate(input$checkGroupParam)
root_path <- isolate(input$pathMandrill)
timeM <- isolate(input$slider_datetime)
timeS <- as.character(timeM[1])
timeE <- as.character(timeM[2])
# Les uuid des mandrill ici 1 mandrill
mandrill_uuid <- isolate(input$uuidMandrill)
if("1" %in% typeD) {
output$temperature <- renderPlot({
path_temperature <- paste0(root_path, "/logLoRaTemp.csv")
preTraitementTemperature(root_path, path_temperature, mandrill_uuid, timeS, timeE)
mandrill_temperature <- readCSVTemperature(paste0(root_path, "/temperature.csv"))
pathTemperature <- paste0(root_path, "/temperature_ext.xlsx")
if(!file.exists(pathTemperature)) {
extTemperature <- data.frame(date=as.character(), uuid=as.character(), temperature=as.numeric())
} else {
extTemperature <- extractExtTemperature(pathTemperature, timeS, timeE)
}
minT <- min(mandrill_temperature$temperature, extTemperature$temperature)
maxT <- max(mandrill_temperature$temperature, extTemperature$temperature)
minD <- min(mandrill_temperature$date)
maxD <- max(mandrill_temperature$date)
uuid <- unique(mandrill_temperature$uuid)
color_mandrill <- distinctColorPalette(length(uuid))
color_mandrill[1] <- "blue"
mandrill <- filter(mandrill_temperature, uuid == uuid[1])
p <-plot(mandrill$date,mandrill$temperature,type="l", col=color_mandrill[1], xlim = c(minD, maxD), ylim=c(minT, maxT), main="Temperature",lwd = 3)
p <- p + abline(h=mean(mandrill$temperature), col=color_mandrill[1], lty=2)
if(length(uuid) > 1) {
for(index in c(2:length(uuid))) {
mandrill <- filter(mandrill_temperature, uuid == uuid[index])
p <- p + lines(mandrill$date,mandrill$temperature, col=color_mandrill[index],lwd = 3)
p <- p + abline(h=mean(mandrill$temperature), col=color_mandrill[index], lty=2)
}
}
if(nrow(extTemperature) > 0) {
p <- p + lines(extTemperature$date,extTemperature$temperature, col="red", lwd = 3)
p <- p + abline(h=mean(extTemperature$temperature), col="red", lty=2)
}
p
})
} else {
output$temperature <- renderPlot({ plot.new()})
}
if("2" %in% typeD || "3" %in% typeD || "4" %in% typeD) {
path_mouvement <- paste0(root_path, "/logLoRaMov.csv")
preTraitementMouvement(root_path, path_mouvement, mandrill_uuid, timeS, timeE)
mandrill_mouvement <- readCSVMouvement(paste0(root_path, "/mouvement.csv"))
path_acceleration <- paste0(root_path, "/logLoRaAcc.csv")
preTraitementAcceleration(root_path, path_acceleration, mandrill_uuid, timeS, timeE)
mandrill_acceleration <- readCSVAcceleration(paste0(root_path, "/acceleration.csv"))
uuid <- unique(mandrill_mouvement$uuid)
minMA <- 0
maxMA <- 255
minD <- min(mandrill_mouvement$date, mandrill_acceleration$date)
maxD <- max(mandrill_mouvement$date, mandrill_acceleration$date)
color_mandrill <- distinctColorPalette(length(uuid)+1)
if("2" %in% typeD) {
output$accX <- renderPlot({
mandrillM <- filter(mandrill_mouvement, uuid == uuid[1])
mandrillA <- filter(mandrill_acceleration, uuid == uuid[1])
par(mfrow=c(2,1))
p <- plot(mandrillM$date,mandrillM$mouvement,type="l", col="purple", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Mouvement")
if(nrow(mandrill_acceleration) > 0) {
p <- p + plot(mandrillA$date,mandrillA$x,type="l", col="blue", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Acceleration X")
}
p
})
} else {
output$accX <- renderPlot({ plot.new()})
}
if("3" %in% typeD) {
output$accY <- renderPlot({
mandrillM <- filter(mandrill_mouvement, uuid == uuid[1])
mandrillA <- filter(mandrill_acceleration, uuid == uuid[1])
par(mfrow=c(2,1))
p <- plot(mandrillM$date,mandrillM$mouvement,type="l", col="purple", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Mouvement")
if(nrow(mandrill_acceleration) > 0) {
p <- p + plot(mandrillA$date,mandrillA$y,type="l", col="red", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Acceleration Y")
}
})
} else {
output$accY <- renderPlot({ plot.new()})
}
if("4" %in% typeD) {
output$accZ <- renderPlot({
mandrillM <- filter(mandrill_mouvement, uuid == uuid[1])
mandrillA <- filter(mandrill_acceleration, uuid == uuid[1])
par(mfrow=c(2,1))
p <- plot(mandrillM$date,mandrillM$mouvement,type="l", col="purple", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Mouvement")
if(nrow(mandrill_acceleration) > 0) {
p <- p + plot(mandrillA$date,mandrillA$z,type="l", col="green", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Acceleration Z")
}
})
} else {
output$accZ <- renderPlot({ plot.new()})
}
} else {
output$accX <- renderPlot({ plot.new()})
output$accY <- renderPlot({ plot.new()})
output$accZ <- renderPlot({ plot.new()})
}
})
\ No newline at end of file
#gifrunning {
position: absolute;
z-index: -1;
}
Shiny.addCustomMessageHandler("stop_gear",
function(value) {
document.getElementById("gifrunning").style.zIndex = "-1";
});
Shiny.addCustomMessageHandler("start_gear",
function(value) {
document.getElementById("gifrunning").style.zIndex = "10";
});
<div class="center_gear"><img id="gifrunning" src="./loading-gears-animation.gif" alt="ruuning"></div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment