geposanui/R/results.R

106 lines
2.8 KiB
R

#' Construct UI for the detailed results panel.
#' @noRd
results_ui <- function(id) {
verticalLayout(
div(
style = "margin-top: 16px",
splitLayout(
cellWidths = "auto",
uiOutput(NS(id, "copy")),
downloadButton(NS(id, "download"), "Download CSV")
)
),
div(
style = "margin-top: 16px",
DT::DTOutput(NS(id, "genes"))
)
)
}
#' Server for the detailed results panel.
#'
#' @param filtered_results A reactive containing the prefiltered results to be
#' displayed.
#'
#' @noRd
results_server <- function(id, filtered_results) {
moduleServer(id, function(input, output, session) {
output$copy <- renderUI({
results <- filtered_results()
gene_ids <- results[, gene]
names <- results[name != "", name]
genes_text <- paste(gene_ids, collapse = "\n")
names_text <- paste(names, collapse = "\n")
splitLayout(
cellWidths = "auto",
rclipboard::rclipButton(
"copy_ids_button",
"Copy gene IDs",
genes_text,
icon = icon("clipboard")
),
rclipboard::rclipButton(
"copy_names_button",
"Copy gene names",
names_text,
icon = icon("clipboard")
)
)
})
columns <- c(
"rank",
"gene",
"name",
"chromosome",
method_ids,
"score",
"percentile"
)
column_names <- c(
"",
"Gene",
"",
"Chromosome",
method_names,
"Score",
"Percentile"
)
output_data <- reactive({
filtered_results()[, ..columns]
})
output$download <- downloadHandler(
filename = "geposan_filtered_results.csv",
content = function(file) {
fwrite(output_data(), file = file)
},
contentType = "text/csv"
)
output$genes <- DT::renderDT({
dt <- DT::datatable(
output_data(),
rownames = FALSE,
colnames = column_names,
style = "bootstrap",
options = list(
rowCallback = js_link,
columnDefs = list(list(visible = FALSE, targets = 2)),
pageLength = 25
)
)
DT::formatPercentage(
dt,
c(method_ids, "score", "percentile"),
digits = 2
)
})
})
}