mirror of
https://github.com/johrpan/geposanui.git
synced 2025-10-26 19:27:24 +01:00
Start adding an UI using Shiny
This commit is contained in:
parent
be696b91a0
commit
5d59018b2e
4 changed files with 118 additions and 3 deletions
8
main.R
8
main.R
|
|
@ -1,4 +1,6 @@
|
||||||
source("data.R")
|
library(shiny)
|
||||||
|
|
||||||
data <- load_data_cached("input")
|
source("server.R")
|
||||||
print(data)
|
source("ui.R")
|
||||||
|
|
||||||
|
runApp(shinyApp(ui, server))
|
||||||
73
scatter_plot.R
Normal file
73
scatter_plot.R
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
library(data.table)
|
||||||
|
library(ggplot2)
|
||||||
|
|
||||||
|
#' Draw a scatter plot containing gene positions.
|
||||||
|
scatter_plot <- function(gene_ids, data) {
|
||||||
|
species <- data$species
|
||||||
|
setorder(species, median_distance)
|
||||||
|
|
||||||
|
distances <- data$distances[geneid %in% gene_ids]
|
||||||
|
|
||||||
|
plot <- ggplot() +
|
||||||
|
scale_x_continuous(
|
||||||
|
name = "Species",
|
||||||
|
breaks = seq_len(nrow(species)),
|
||||||
|
labels = species$label
|
||||||
|
) +
|
||||||
|
scale_y_continuous(name = "Distance to telomeres [Mbp]") +
|
||||||
|
geom_line(
|
||||||
|
species,
|
||||||
|
mapping = aes(
|
||||||
|
x = as.numeric(rownames(species)),
|
||||||
|
y = median_distance / 1000000
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
colors <- rainbow(length(gene_ids))
|
||||||
|
|
||||||
|
for (i in seq_len(length(gene_ids))) {
|
||||||
|
gene_id <- gene_ids[i]
|
||||||
|
|
||||||
|
gene_distances <- data.table(
|
||||||
|
index = as.numeric(rownames(species)),
|
||||||
|
distance = unlist(distances[geneid == gene_id, -1])
|
||||||
|
)
|
||||||
|
|
||||||
|
plot <- plot +
|
||||||
|
geom_point(
|
||||||
|
gene_distances,
|
||||||
|
mapping = aes(
|
||||||
|
x = index,
|
||||||
|
y = distance / 1000000,
|
||||||
|
),
|
||||||
|
color = colors[i]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
plot
|
||||||
|
|
||||||
|
# plot(
|
||||||
|
# species[, median_distance] / 1000000,
|
||||||
|
# type = "l",
|
||||||
|
# xaxt = "n",
|
||||||
|
# xlab = "",
|
||||||
|
# ylab = "Distance to telomere (Mbp)",
|
||||||
|
# bty = "n"
|
||||||
|
# )
|
||||||
|
|
||||||
|
# axis(
|
||||||
|
# 1,
|
||||||
|
# at = seq_len(nrow(species)),
|
||||||
|
# tick = FALSE,
|
||||||
|
# labels = FALSE
|
||||||
|
# )
|
||||||
|
|
||||||
|
# mtext(
|
||||||
|
# data$species[, label],
|
||||||
|
# side = 1,
|
||||||
|
# at = seq_len(nrow(species)),
|
||||||
|
# las = 2,
|
||||||
|
# # col = axis.labels.col,
|
||||||
|
# adj = 1
|
||||||
|
# )
|
||||||
|
}
|
||||||
23
server.R
Normal file
23
server.R
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
library(data.table)
|
||||||
|
library(DT)
|
||||||
|
library(shiny)
|
||||||
|
|
||||||
|
source("data.R")
|
||||||
|
source("scatter_plot.R")
|
||||||
|
|
||||||
|
data <- load_data_cached("input")
|
||||||
|
|
||||||
|
server <- function(input, output) {
|
||||||
|
output$genes <- renderDT({
|
||||||
|
datatable(
|
||||||
|
data$genes[, c("name", "chromosome")],
|
||||||
|
rownames = FALSE,
|
||||||
|
style = "bootstrap"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
output$scatter <- renderPlot({
|
||||||
|
gene_ids <- data$genes[input$genes_rows_selected, id]
|
||||||
|
scatter_plot(gene_ids, data)
|
||||||
|
})
|
||||||
|
}
|
||||||
17
ui.R
Normal file
17
ui.R
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
library(DT)
|
||||||
|
library(shiny)
|
||||||
|
|
||||||
|
ui <- fluidPage(
|
||||||
|
titlePanel("TPE-OLD candidates"),
|
||||||
|
sidebarLayout(
|
||||||
|
position = "right",
|
||||||
|
sidebarPanel(
|
||||||
|
h3("Candidate selection"),
|
||||||
|
DTOutput("genes"),
|
||||||
|
width = 3
|
||||||
|
),
|
||||||
|
mainPanel(
|
||||||
|
plotOutput("scatter"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue