Skip to content

Commit

Permalink
solves and closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
romunov committed Oct 7, 2017
2 parents a59f9ac + 7873368 commit 6d780de
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(DT)
library(sp)
library(rgdal)
library(data.table)
library(ggplot2)

source("global.R")
source("functions.R")
Expand All @@ -29,7 +30,6 @@ sidebar <- dashboardSidebar(
)
)


#### BODY ####
body <- dashboardBody(
tags$style(type = "text/css", "#map {height: 100% !important;}"),
Expand Down Expand Up @@ -76,8 +76,8 @@ body <- dashboardBody(
uiOutput("view_parentage")
),
tabItem(tabName = "overview",
h3("Quick statistics of dataset"),
uiOutput("stats")
uiOutput("stats"),
uiOutput("graphs")
)
)
)
Expand Down
30 changes: 30 additions & 0 deletions dynamic_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,33 @@ observe({
)
})
})

observe({
xy <- allData()
par <- inputFileParentage()


if(nrow(xy) > 0) {
output$sps <- renderPlot({
ggplot(xy) +
theme_bw() +
geom_bar(aes(sample_type))
})
# output$opp <- renderPlot({
# ggplot(par) +
# theme_bw() +
# geom_col(aes(x = unique(c(mother, father), y = offspring)))
# })
output$graphs <- renderUI({
fluidRow(
box(solidHeader = TRUE, title = "Samples per sample type",
plotOutput("sps"))
# box(solidHeader = TRUE, title = "Number of offspring per parent",
# plotOutput("opp"))
)
})
}


})

25 changes: 14 additions & 11 deletions generate_fake_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,35 @@ N <- 5 # number of points per individual
lng <- c(13.0, 16.6)
lat <- c(45.4, 46.88)
date <- as.Date(c("01.01.2010", "31.12.2017"), format = "%d.%m.%Y")
type <- c("scat", "urine", "saliva", "tissue")
sample_type <- c("scat", "urine", "saliva", "tissue")
sex <- c("M", "F")

ind.pt <- data.frame(lat = runif(NIND, min = min(lat), max = max(lat)),
lng = runif(NIND, min = min(lng), max = max(lng)))
lng = runif(NIND, min = min(lng), max = max(lng)))

ind.pt <- split(ind.pt, f = 1:nrow(ind.pt))

xy <- sapply(ind.pt, FUN = function(x, N) {
out <- data.frame(lng = rnorm(N, mean = x$lng, sd = 0.05),
lat = rnorm(N, mean = x$lat, sd = 0.05))
out <- data.frame(x = rnorm(N, mean = x$lng, sd = 0.05),
y = rnorm(N, mean = x$lat, sd = 0.05))
tm <- sample(seq(from = min(date), to = max(date), by = "day"), 1)
typ <- sample(type, 5, replace = TRUE)
out$time <- tm + (1:N)
out$type <- typ
typ <- sample(sample_type, 5, replace = TRUE)
sex <- sample(sex, 5, replace = TRUE)
out$date <- tm + (1:N)
out$sample_type <- typ
out$sex <- sex
out
}, N = N, simplify = FALSE)

xy <- do.call(rbind, xy)

xy$animal <- sprintf("%.3d", rep(1:NIND, each = N))
xy$id <- as.character(1:nrow(xy))
xy$sample_name <- as.character(1:nrow(xy))

offspring <- data.frame(sibling = sprintf("%.3d", 5:NIND),
mother = c("001", "002"),
father = c("003", "004"),
cluster = c("1", "2"))
mother = c("001", "002"),
father = c("003", "004"),
cluster = c("1", "2"))

write.table(x = xy, file = "data.csv", sep = ",", row.names = FALSE, quote = FALSE)
write.table(x = offspring, file = "offspring.csv", sep = ",", row.names = FALSE, quote = FALSE)
9 changes: 9 additions & 0 deletions leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ output$map <- renderLeaflet({
setView(lng = 14.815333, lat = 46.119944, zoom = 8)
})

observeEvent(input$uploadSampleData_row_last_clicked, {
x <- inputFileSamples()
selectedRow <- input$uploadSampleData_row_last_clicked

leafletProxy('map') %>%
setView(lng = x[selectedRow, 'lng'], lat = x[selectedRow, 'lat'], zoom = 10)

}, ignoreInit = TRUE)

# Add markers and lines for selected animals to map
observe({
PS <- PS()
Expand Down
2 changes: 1 addition & 1 deletion view_data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
output$uploadSampleData <- renderDataTable({
x <- inputFileSamples()
DT::datatable(data = x, filter = "top", options = list(pageLength = 15))
DT::datatable(data = x, filter = "top", options = list(pageLength = 15), selection = 'single')
})

observe({
Expand Down

0 comments on commit 6d780de

Please sign in to comment.