#' Construct UI for the genes table. #' @noRd genes_table_ui <- function(id) { verticalLayout( div( style = "margin-top: 16px", splitLayout( cellWidths = "auto", uiOutput(NS(id, "copy")), downloadButton( NS(id, "download"), "Download CSV", class = "btn-outline-primary" ) ) ), div( style = "margin-top: 16px; margin-bottom: 8px;", DT::DTOutput(NS(id, "genes")) ) ) } #' Server for the genes table. #' #' @param data A reactive containing the results to be displayed. #' #' @noRd genes_table_server <- function(id, data) { moduleServer(id, function(input, output, session) { output$copy <- renderUI({ data <- data() gene_ids <- data[, gene] names <- data[hgnc_name != "", hgnc_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"), class = "btn-outline-primary" ), rclipboard::rclipButton( "copy_names_button", "Copy HGNC symbols", names_text, icon = icon("clipboard"), class = "btn-outline-primary" ) ) }) output$download <- downloadHandler( filename = "ubigen.csv", content = \(file) fwrite(data(), file = file), contentType = "text/csv" ) output$genes <- DT::renderDT({ DT::datatable( data()[, .( "Gene" = glue::glue_data( data(), "{hgnc_name}" ), "Rank" = rank, "Percentile" = percentile, "Score" = score, "Median" = median_expression, "Mean" = mean_expression, "Standard deviation" = sd_expression, "Expressed" = above_zero, "Above median" = above_median, "Above 95%" = above_95 )], options = list( dom = "frtip", pageLength = 100 ), rownames = FALSE, escape = FALSE, selection = "none" ) |> DT::formatPercentage( c( "Percentile", "Score", "Expressed", "Above median", "Above 95%" ), digits = 2, ) |> DT::formatRound(c( "Median", "Mean", "Standard deviation" )) }) }) }