mirror of
https://github.com/johrpan/ubigen.git
synced 2025-10-26 19:57:24 +01:00
Add score distribution plot
This commit is contained in:
parent
276730f217
commit
1a47b30dbf
3 changed files with 55 additions and 1 deletions
|
|
@ -23,5 +23,6 @@ Imports:
|
||||||
bslib,
|
bslib,
|
||||||
data.table,
|
data.table,
|
||||||
DT,
|
DT,
|
||||||
|
plotly,
|
||||||
glue,
|
glue,
|
||||||
shiny
|
shiny
|
||||||
|
|
|
||||||
43
R/server.R
43
R/server.R
|
|
@ -21,9 +21,52 @@ server <- function(input, output) {
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|
||||||
|
output$scores_plot <- plotly::renderPlotly(scores_plot(ranked_data()))
|
||||||
output$ranked_data <- DT::renderDataTable(genes_table(ranked_data()))
|
output$ranked_data <- DT::renderDataTable(genes_table(ranked_data()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#' Create plot showing the distribution of scores using `plotly`.
|
||||||
|
#'
|
||||||
|
#' @param ranked_data Data on genes with precomputed ranks.
|
||||||
|
#' @param ranks How may ranks the x-axis should include. If this parameter is
|
||||||
|
#' `NULL`, all ranks will be shown.
|
||||||
|
#'
|
||||||
|
#' @return A `plotly` figure for rendering.
|
||||||
|
#' @noRd
|
||||||
|
scores_plot <- function(ranked_data, ranks = 1000) {
|
||||||
|
data <- if (is.null(ranks)) {
|
||||||
|
ranked_data
|
||||||
|
} else {
|
||||||
|
ranked_data[1:ranks]
|
||||||
|
}
|
||||||
|
|
||||||
|
ranks_label <- if (is.null(ranks)) {
|
||||||
|
"Ranks"
|
||||||
|
} else {
|
||||||
|
glue::glue("Ranks (1 to {ranks})")
|
||||||
|
}
|
||||||
|
|
||||||
|
plotly::plot_ly() |>
|
||||||
|
plotly::add_markers(
|
||||||
|
data = data,
|
||||||
|
x = ~rank,
|
||||||
|
y = ~score,
|
||||||
|
text = ~hgnc_name,
|
||||||
|
customdata = ~percentile,
|
||||||
|
hovertemplate = paste0(
|
||||||
|
"<b>%{text}</b><br>",
|
||||||
|
"Rank: %{x}<br>",
|
||||||
|
"Score: %{y:.2}<br>",
|
||||||
|
"Percentile: %{customdata:.2%}",
|
||||||
|
"<extra></extra>"
|
||||||
|
)
|
||||||
|
) |>
|
||||||
|
plotly::layout(
|
||||||
|
xaxis = list(title = ranks_label),
|
||||||
|
yaxis = list(title = "Score")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#' Create a displayable data table from the gene results data.
|
#' Create a displayable data table from the gene results data.
|
||||||
#' @noRd
|
#' @noRd
|
||||||
genes_table <- function(data) {
|
genes_table <- function(data) {
|
||||||
|
|
|
||||||
10
R/ui.R
10
R/ui.R
|
|
@ -41,9 +41,19 @@ ui <- function() {
|
||||||
),
|
),
|
||||||
mainPanel(
|
mainPanel(
|
||||||
width = 9,
|
width = 9,
|
||||||
|
tabsetPanel(
|
||||||
|
type = "pills",
|
||||||
|
tabPanel(
|
||||||
|
title = "Distribution of scores",
|
||||||
|
plotly::plotlyOutput("scores_plot")
|
||||||
|
),
|
||||||
|
tabPanel(
|
||||||
|
title = "Detailed results",
|
||||||
DT::dataTableOutput("ranked_data")
|
DT::dataTableOutput("ranked_data")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
),
|
),
|
||||||
tabPanel(
|
tabPanel(
|
||||||
title = "Help"
|
title = "Help"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue