diff --git a/Dashboard/global.R b/Dashboard/global.R index 332d5f4..5df8ec6 100644 --- a/Dashboard/global.R +++ b/Dashboard/global.R @@ -11,7 +11,7 @@ library(htmltools) library(GenomicDataCommons) library(DT) library(BiocManager) -options(repos = BiocManager::repositories()) +# options(repos = BiocManager::repositories()) load(file = "tcga.RData") tcga_project_ids_list <- c("TODOS", tcga_project_ids_list) @@ -21,8 +21,13 @@ projects <- GenomicDataCommons::projects() %>% GenomicDataCommons::facet(c("name", "project_id")) %>% results_all() +vb_style <- function(msg = '', style="font-size: 100%;") { + tags$p( msg , style = style ) +} + Sys.setenv(OPENSSL_CONF = "/dev/null") options(shiny.fullstacktrace = TRUE) source("explorer.R") +source("project.R") diff --git a/Dashboard/project.R b/Dashboard/project.R new file mode 100644 index 0000000..862090d --- /dev/null +++ b/Dashboard/project.R @@ -0,0 +1,269 @@ +# project_disease_type_treemap ---- +project_disease_type_treemap <- function(data) { + project_disease_type_tree <- data %>% + group_by(project_id, disease_type) %>% + tally(name = "Casos") %>% + mutate( + disease_type = paste( + Casos, disease_type + ) + ) %>% + rename( + "parent" = 1, + "label" = 2 + ) + + project_disease_type_tree <- data %>% + dplyr::select(project_id) %>% + mutate( + parent = "Número de casos por proyecto y por tipo de enfermedad" + ) %>% + group_by(parent, project_id) %>% + tally(name = "Casos") %>% + rename( + "parent" = 1, + "label" = 2 + ) %>% + rbind(., project_disease_type_tree) %>% + replace(is.na(.), "Sin dato") + + # project_disease_type_treemap ---- + project_disease_type_treemap <- plot_ly( + data = project_disease_type_tree, + branchvalues = "total", + type = "treemap", + #ids = ~ids, + labels = ~label, + parents = ~parent, + values = ~Casos + ) + + return(project_disease_type_treemap) +} + +project_disease_type_treedt <- function(data) { + data <- data %>% + group_by(project_id, disease_type) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename( + "Proyecto" = 1, + "Tipo de enfermedad" = 2 + ) %>% + datatable( + extensions = "Buttons", + rownames = FALSE, + options = list( + language = list( + url = "//cdn.datatables.net/plug-ins/1.13.7/i18n/es-ES.json" + ), + dom = "Bfrtip", + buttons = list( + list( + extend = "csv", + filename = "casos_por_proyecto_tipo_enfermedad" + ), + list( + extend = "excel", + filename = "casos_por_proyecto_tipo_enfermedad" + ) + ), + paging = FALSE, + scrollY = "400px", + scrollX = TRUE + ) + ) + return(data) +} + +# project_bar ---- +project_bar <- function(data) { + fig <- data %>% + group_by(project_id) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Proyecto" = 1) %>% + plot_ly( + x = ~Proyecto, y = ~`Número de casos`, type = "bar" + ) %>% + layout( + xaxis = list( + title = "Proyecto", + categoryorder = "total descending" + ), + yaxis = list( + title = "Número de casos" + ) + ) %>% + config( + displaylogo = FALSE, + modeBarButtonsToRemove = c( + "sendDataToCloud", "editInChartStudio", "pan2d", "select2d", + "drawclosedpath", "drawline", "drawrect", "drawopenpath", + "drawcircle", "eraseshape", "zoomIn2d", "zoomOut2d", "toggleSpikelines", + "lasso2d" + ) + ) + return(fig) +} + +# project_bardt ---- +project_bardt <- function(data) { + data <- data %>% + group_by(project_id, project_name) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Proyecto" = 1, "Nombre" = 2) %>% + datatable( + extensions = "Buttons", + rownames = FALSE, + options = list( + language = list( + url = "//cdn.datatables.net/plug-ins/1.13.7/i18n/es-ES.json" + ), + dom = "Bfrtip", + buttons = list( + list( + extend = "csv", + filename = "casos_por_proyecto" + ), + list( + extend = "excel", + filename = "casos_por_proyecto" + ) + ), + paging = FALSE, + scrollY = "400px", + scrollX = TRUE + ) + ) + return(data) +} + +# disease_type_bar ---- +disease_type_bar <- function(data) { + fig <- data %>% + group_by(disease_type) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Tipo de enfermedad" = 1) %>% + plot_ly( + x = ~`Tipo de enfermedad`, y = ~`Número de casos`, type = "bar" + ) %>% + layout( + xaxis = list( + title = "Tipo de enfermedad", + categoryorder = "total descending" + ), + yaxis = list( + title = "Número de casos" + ) + ) %>% + config( + displaylogo = FALSE, + modeBarButtonsToRemove = c( + "sendDataToCloud", "editInChartStudio", "pan2d", "select2d", + "drawclosedpath", "drawline", "drawrect", "drawopenpath", + "drawcircle", "eraseshape", "zoomIn2d", "zoomOut2d", "toggleSpikelines", + "lasso2d" + ) + ) + return(fig) +} + +# disease_type_bardt ---- +disease_type_bardt <- function(data) { + data <- data %>% + group_by(disease_type) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Tipo de enfermedad" = 1) %>% + datatable( + extensions = "Buttons", + rownames = FALSE, + options = list( + language = list( + url = "//cdn.datatables.net/plug-ins/1.13.7/i18n/es-ES.json" + ), + dom = "Bfrtip", + buttons = list( + list( + extend = "csv", + filename = "casos_por_tipo_enfermedad" + ), + list( + extend = "excel", + filename = "casos_por_tipo_enfermedad" + ) + ), + paging = FALSE, + scrollY = "400px", + scrollX = TRUE + ) + ) + return(data) +} + +# primary_site_bar ---- +primary_site_bar <- function(data) { + data <- data %>% + group_by(primary_site) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Sitio primario" = 1) + + xticks_labels <- as.list(substr(data$`Sitio primario`, 1, 30)) + + fig <- plot_ly( + data, + x = ~`Sitio primario`, y = ~`Número de casos`, type = "bar" + ) %>% + layout( + xaxis = list( + title = "Sitio primario", + categoryorder = "total descending", + ticktext = xticks_labels, + tickvals = as.list(c(0:nrow(data))), + tickmode = "array" + ), + yaxis = list( + title = "Número de casos" + ) + ) %>% + config( + displaylogo = FALSE, + modeBarButtonsToRemove = c( + "sendDataToCloud", "editInChartStudio", "pan2d", "select2d", + "drawclosedpath", "drawline", "drawrect", "drawopenpath", + "drawcircle", "eraseshape", "zoomIn2d", "zoomOut2d", "toggleSpikelines", + "lasso2d" + ) + ) + return(fig) +} + +# primary_site_bardt ---- +primary_site_bardt <- function(data) { + data <- data %>% + group_by(primary_site) %>% + tally(name = "Número de casos", sort = TRUE) %>% + rename("Sitio primario" = 1) %>% + datatable( + extensions = "Buttons", + rownames = FALSE, + options = list( + language = list( + url = "//cdn.datatables.net/plug-ins/1.13.7/i18n/es-ES.json" + ), + dom = "Bfrtip", + buttons = list( + list( + extend = "csv", + filename = "casos_por_sitio_primario" + ), + list( + extend = "excel", + filename = "casos_por_sitio_primario" + ) + ), + paging = FALSE, + scrollY = "400px", + scrollX = TRUE + ) + ) + return(data) +} diff --git a/Dashboard/server.R b/Dashboard/server.R index 98e375f..bd11148 100644 --- a/Dashboard/server.R +++ b/Dashboard/server.R @@ -98,6 +98,142 @@ function(input, output, session) { selected = input$primary_site ) }) + + ## Explorer ---- + ### Value boxes ---- + box_data <- reactiveValues() + box_data$proyectos <- 0 + box_data$casos <- 0 + box_data$disease_type <- 0 + + #### Observe project_id ---- + observeEvent(input$project_id, { + box_data$proyectos <- length( + unique(combined_cases_reactive()$project_id) + ) + box_data$casos <- length( + unique(combined_cases_reactive()$case_id) + ) + box_data$disease_type <- length( + unique(combined_cases_reactive()$disease_type) + ) + }) + + #### Observe disease_type ---- + observeEvent(input$disease_type, { + box_data$proyectos <- length( + unique(combined_cases_reactive()$project_id) + ) + box_data$casos <- length( + unique(combined_cases_reactive()$case_id) + ) + box_data$disease_type <- length( + unique(combined_cases_reactive()$disease_type) + ) + }) + + #### Observe primary_site ---- + observeEvent(input$primary_site, { + box_data$proyectos <- length( + unique(combined_cases_reactive()$project_id) + ) + box_data$casos <- length( + unique(combined_cases_reactive()$case_id) + ) + box_data$disease_type <- length( + unique(combined_cases_reactive()$disease_type) + ) + }) + + #### Boxes ---- + ##### Proyectos ---- + output$box_proyectos <- renderValueBox({ + valueBox( + vb_style( + box_data$proyectos, "font-size: 90%;" + ), + vb_style( + "Número de proyectos", "font-size: 95%;" + ), + icon = icon("wand-magic-sparkles"), + color = "purple" + ) + }) + + ##### Casos ---- + output$box_casos <- renderValueBox({ + valueBox( + vb_style( + box_data$casos, "font-size: 90%;" + ), + vb_style( + "Número de casos", "font-size: 95%;" + ), + icon = icon("user"), + color = "purple" + ) + }) + + ##### disease_type ---- + output$box_disease_type <- renderValueBox({ + valueBox( + vb_style( + box_data$disease_type, "font-size: 90%;" + ), + vb_style( + "Número de tipos de enfermedad", "font-size: 95%;" + ), + icon = icon("disease"), + color = "purple" + ) + }) + + ### Project ---- + #### project_disease_type_treemap ---- + output$project_disease_type_treemap <- renderPlotly({ + project_disease_type_treemap(combined_cases_reactive()) + }) + + #### project_disease_type_treedt ---- + output$project_disease_type_treedt <- DT::renderDataTable({ + project_disease_type_treedt(combined_cases_reactive()) + }) + + #### project_bar ---- + output$project_bar <- renderPlotly({ + project_bar(combined_cases_reactive()) + }) + + #### project_bardt ---- + output$project_bardt <- DT::renderDataTable({ + project_bardt(combined_cases_reactive()) + }) + + #### disease_type ---- + output$disease_type_bar <- renderPlotly({ + disease_type_bar(combined_cases_reactive()) + }) + + #### disease_typedt ---- + output$disease_type_bardt <- DT::renderDataTable({ + disease_type_bardt(combined_cases_reactive()) + }) + + #### primary_site_bar ---- + output$primary_site_bar <- renderPlotly({ + primary_site_bar(combined_cases_reactive()) + }) + + #### primary_site_bardt ---- + output$primary_site_bardt <- DT::renderDataTable({ + primary_site_bardt(combined_cases_reactive()) + }) + + + + + + # Explorer data ---- explorer_data_reactive <- reactive({ @@ -142,6 +278,8 @@ function(input, output, session) { )) %>% aggregations() }) + + ## project_id ---- ### barplot ---- diff --git a/Dashboard/ui.R b/Dashboard/ui.R index 27ec9ba..6823a5e 100644 --- a/Dashboard/ui.R +++ b/Dashboard/ui.R @@ -50,7 +50,7 @@ fluidPage( ### primary_site ---- selectInput( "primary_site", - label = "Primary site", + label = "Sitio primario", choices = c("TODOS"), selected = "TODOS" ), @@ -94,8 +94,119 @@ fluidPage( ) ), tabItems( + ## Tab EXPLORADOR ---- tabItem( - tabName = "EXPLORADOR" + tabName = "EXPLORADOR", + fluidRow( + valueBoxOutput("box_proyectos", width = 4), + valueBoxOutput("box_casos", width = 4), + valueBoxOutput("box_disease_type", width = 4) + ), + fluidRow( + width = 12, + box( + width = 12, + solidHeader = TRUE, + collapsible = TRUE, + title = "Proyectos", + tabBox( + width = 12, + height = NULL, + ### project_disease_type_treemap ---- + tabPanel( + title = "Mapa de arbol", + icon = icon("table-cells"), + shinycssloaders::withSpinner( + plotlyOutput( + "project_disease_type_treemap", + height = 500 + ), + color = "#1c9ad6", type = "8", size = 0.5 + ), + tags$caption( + class = "text-center", + style = "caption-side: bottom; text-align: center;", + em("Prueba hacer click para expandir la información") + ) + ), + ### project_disease_type_treedt ---- + tabPanel( + title = "Cuadro de datos del mapa de arbol", + icon = icon("table"), + shinycssloaders::withSpinner( + DT::dataTableOutput("project_disease_type_treedt"), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### project_bar ---- + tabPanel( + title = "Gráfico de barras por proyecto", + icon = icon("chart-bar"), + h4( + class = "text-center", + "Número de Casos por Proyecto" + ), + shinycssloaders::withSpinner( + plotlyOutput("project_bar", height = 500), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### project_bardt ---- + tabPanel( + title = "Cuadro de datos por proyecto", + icon = icon("table"), + shinycssloaders::withSpinner( + DT::dataTableOutput("project_bardt"), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### disease_type_bar ---- + tabPanel( + title = "Gráfico de barras por Tipo de Enfermedad", + icon = icon("chart-bar"), + h4( + class = "text-center", + "Número de Casos por Tipo de Enfermedad" + ), + shinycssloaders::withSpinner( + plotlyOutput("disease_type_bar", height = 500), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### disease_type_bardt ---- + tabPanel( + title = "Cuadro de datos por tipo de enfermedad", + icon = icon("table"), + shinycssloaders::withSpinner( + DT::dataTableOutput("disease_type_bardt"), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### primary_site_bar ---- + tabPanel( + title = "Gráfico de barras por sitio primario", + icon = icon("chart-bar"), + h4( + class = "text-center", + "Número de Casos por Sitio Primario" + ), + shinycssloaders::withSpinner( + plotlyOutput("primary_site_bar", height = 500), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ), + ### primary_site_bardt ---- + tabPanel( + title = "Cuadro de datos por sitio primario", + icon = icon("table"), + shinycssloaders::withSpinner( + DT::dataTableOutput("primary_site_bardt"), + color = "#1c9ad6", type = "8", size = 0.5 + ) + ) + ) + ) + ) ), ## Tab EXPLORADOROLD ---- tabItem(