Commit 9f9dcc83 authored by jlopez's avatar jlopez
Browse files

first draft shiny server

parents
distance3D <- function(a, b) {
return(sqrt((b[1] - a[1])^2 + (b[2] - a[2])^2 + (b[3] - a[3])^2))
}
importDataMosquito <- function(path) {
data <- NULL
ext <- file_ext(path)
if(ext == "csv") {
data <- read.csv2(path, dec = ".")
} else if(ext == "txt") {
data <- read.table(path,header=TRUE)
}
data <- data %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z))
id <- unique(data$object)
size <- length(id)
tabMinMax <- data.frame(id = id, min = rep(0, size), max = rep(0, size), minX = rep(0, size), minY = rep(0, size), minZ = rep(0, size), maxX = rep(0, size), maxY = rep(0, size), maxZ = rep(0, size))
for(index in 1:size) {
currentM <- data %>% filter(object == tabMinMax[index,]$id)
#currentM <- currentM %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z))
tabMinMax[index,]$minX <- currentM[1,]$X
tabMinMax[index,]$minY <- currentM[1,]$Y
tabMinMax[index,]$minZ <- currentM[1,]$Z
tabMinMax[index,]$maxX <- currentM[nrow(currentM),]$X
tabMinMax[index,]$maxY <- currentM[nrow(currentM),]$Y
tabMinMax[index,]$maxZ <- currentM[nrow(currentM),]$Z
tabMinMax[index,]$min = min(currentM$time, na.rm = TRUE)
tabMinMax[index,]$max = max(currentM$time, na.rm = TRUE)
}
minM <- min(tabMinMax$min)
maxM <- max(tabMinMax$max)
mosquitoT1 <- tabMinMax %>% select(id, min) %>% rename(time = min)
mosquitoT2 <- tabMinMax %>% select(id, max) %>% rename(time = max)
mosquitoT <- rbind(mosquitoT1, mosquitoT2) %>% arrange(id)
return(mosquitoT)
}
\ No newline at end of file
MenuGauche = sidebarMenu(id = "sidebarmenu",
menuItem("Home", tabName = "Home", icon = icon("home", lib="font-awesome")),
tags$br(), tags$br(),
selectInput("selectMosquito", "Show born mosquito", c(), multiple = TRUE),
selectInput("pathMosquito", "Construct path mosquito", c(), multiple = TRUE),
actionButton("filterMosquito", "Filter", style = "primary"),
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 )
)
)
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
library(shiny)
library(shinydashboard)
library(shinyjs)
library(DT)
library(dplyr)
library(devtools)
library(randomcoloR)
library(ggplot2)
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')
#style <- tags$style(HTML(readLines("www/added_styles.css")) )
UI <- dashboardPage(
skin = "blue",
dashboardHeader(title = "RMosquito"),
dashboardSidebar(MenuGauche),
dashboardBody(
shinyjs::useShinyjs(),
#extendShinyjs(text = jscode),
tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.min.readable.css")) ,
#tags$head(style),
tabItems(
tabItem(tabName = "Home", tabHome)
)
)
)
server <- function( input, output, session) {
tutu <<- NULL
listM <<- c()
source("./server/opt_home.R", local=TRUE)
}
shinyApp(ui = UI, server = server)
\ No newline at end of file
tabHome = fluidPage(align="left",
column(width = 12,
fileInput("dataMosquito", "Choose CSV File",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
plotOutput("plotRawData", height = "1600px")
)
)
\ No newline at end of file
output$plotRawData = renderPlot({
req(input$dataMosquito)
path <- input$dataMosquito$datapath
mosquitoT <- importDataMosquito(path)
dataM <<- mosquitoT
color_mosquito <<- distinctColorPalette(nrow(mosquitoT)/2)
color_mosquito[1] <<- "#000000"
uuid = unique(dataM$id)
updateSelectInput(session, "selectMosquito",
label = "Select mosquito",
choices = uuid,
selected = uuid[1]
)
updateSelectInput(session, "pathMosquito",
label = "Construct path mosquito",
choices = uuid
)
vertical_id <- c(uuid[1])
p1 <- ggplot()
if(length(uuid) > 1) {
for(index in c(1:length(uuid))) {
mosquito <- filter(mosquitoT, id == uuid[index])
p1 <- p1 + geom_line(aes(y = id, x = time), size=1.5, colour = color_mosquito[index],
data = mosquito)
if(uuid[index] %in% vertical_id) {
p1 <- p1 +geom_vline(aes(xintercept = time), size=0.5, mosquito, linetype = "dashed", colour = color_mosquito[index])
}
}
}
p1 <- p1 + scale_y_continuous(breaks=uuid)
p1
}, once = TRUE)
observeEvent(input$filterMosquito, {
vertical_id <- c(input$selectMosquito)
FilterUUID <- c()
uuid = unique(dataM$id)
if(!is.null(input$pathMosquito)) {
listM <- c(input$pathMosquito)
findM <- dataM %>% filter(id %in% listM)
maxM <- max(findM$time)
newt_uuid <- c()
if(length(uuid) > 1) {
for(index in c(1:length(uuid))) {
mosquito <- filter(dataM, id == uuid[index])
if(min(mosquito$time) >= maxM) {
newt_uuid <- c(newt_uuid, index)
}
}
}
FilterUUID <- unique(c(newt_uuid, listM))
updateSelectInput(session, "pathMosquito",
label = "Construct path mosquito",
choices = FilterUUID,
selected = listM)
} else {
updateSelectInput(session, "pathMosquito",
label = "Construct path mosquito",
choices = uuid)
}
output$plotRawData = renderPlot({
mosquitoT <- dataM
uuid = unique(mosquitoT$id)
p1 <- ggplot()
if(length(uuid) > 1) {
for(index in c(1:length(uuid))) {
mosquito <- filter(mosquitoT, id == uuid[index])
if(length(FilterUUID) > 0) {
if(mosquito$id[1] %in% FilterUUID) {
p1 <- p1 + geom_line(aes(y = id, x = time), size=1.5, colour = color_mosquito[index],
data = mosquito)
if(uuid[index] %in% vertical_id) {
p1 <- p1 +geom_vline(aes(xintercept = time), size=0.5, mosquito, linetype = "dashed", colour = color_mosquito[index])
}
}
} else {
p1 <- p1 + geom_line(aes(y = id, x = time), size=1.5, colour = color_mosquito[index],
data = mosquito)
if(uuid[index] %in% vertical_id) {
p1 <- p1 +geom_vline(aes(xintercept = time), size=0.5, mosquito, linetype = "dashed", colour = color_mosquito[index])
}
}
}
}
p1 <- p1 + scale_y_continuous(breaks=uuid)
p1
}, once = TRUE)
})
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