Skip to content

Commit

Permalink
feat: dashboard filters working reactively
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliversinn committed Dec 15, 2023
1 parent a7ec779 commit 0794595
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 18 deletions.
9 changes: 9 additions & 0 deletions Dashboard/global.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ library(fontawesome)
library(plotly)
library(dplyr)
library(htmltools)
library(GenomicDataCommons)

projects <- GenomicDataCommons::projects() %>%
GenomicDataCommons::filter(program.name == "TCGA") %>%
GenomicDataCommons::facet(c("name", "project_id")) %>%
results_all()

tcga_project_ids_list <- projects$project_id
tcga_project_ids_list <- c("TODOS", tcga_project_ids_list)


Sys.setenv(OPENSSL_CONF = "/dev/null")
Expand Down
64 changes: 64 additions & 0 deletions Dashboard/server.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
function(input, output, session) {
# Filters ---
## projects_reactive ----
projects_reactive <- reactive({
projects <- GenomicDataCommons::projects() %>%
GenomicDataCommons::filter(program.name == "TCGA") %>%
GenomicDataCommons::facet(c("name", "project_id"))

if (input$project_id != "TODOS") {
projects <- projects %>%
GenomicDataCommons::filter(project_id == input$project_id)
}

if (input$disease_type != "TODOS") {
projects <- projects %>%
GenomicDataCommons::filter(disease_type == input$disease_type)
}

if (input$primary_site != "TODOS") {
projects <- projects %>%
GenomicDataCommons::filter(primary_site == input$primary_site)
}

projects <- projects %>%
GenomicDataCommons::results_all()
})

## disease_type filter ----
diseases_types_reactive <- reactive({
unique(
rapply(projects_reactive()$disease_type, function(x) head(x, 100))
)
})

diseases_types_list <- reactive({
c("TODOS", diseases_types_reactive())
})

observe({
updateSelectInput(
session,
"disease_type",
choices = diseases_types_list(),
selected = input$disease_type
)
})

# primary_site filter ----
primary_site_reactive <- reactive({
unique(
rapply(projects_reactive()$primary_site, function(x) head(x, 100))
)
})

primary_site_list <- reactive({
c("TODOS", primary_site_reactive())
})

observe({
updateSelectInput(
session,
"primary_site",
choices = primary_site_list(),
selected = input$primary_site
)
})
}
24 changes: 12 additions & 12 deletions Dashboard/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,33 @@ fluidPage(
### project_id ----
selectInput(
"project_id",
label = "Poject ID",
choices = c("Project 1", "Project 2"),
selected = "Project 1"
label = "Proyecto",
choices = tcga_project_ids_list,
selected = tcga_project_ids_list[1]
),
bsTooltip(
"project_id",
"Seleccionar un proyecto",
placement = "right", trigger = "hover", options = NULL
),
### primary_diagnosis ----
### disease_type ----
selectInput(
"primary_diagnosis",
label = "Primary diagnosis",
choices = c("Diagnosis 1", "Diagnosis 2"),
selected = "Diagnosis 1"
"disease_type",
label = "Tipo de enfermedad",
choices = c("TODOS"),
selected = "TODOS"
),
bsTooltip(
"primary_diagnosis",
"Seleccionar un primary diagnosis",
"disease_type",
"Seleccionar un tipo de enfermedad",
placement = "right", trigger = "hover", options = NULL
),
### primary_site ----
selectInput(
"primary_site",
label = "Primary site",
choices = c("Site 1", "Site 2"),
selected = "Site 1"
choices = c("TODOS"),
selected = "TODOS"
),
bsTooltip(
"primary_site",
Expand Down
16 changes: 11 additions & 5 deletions setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ library(GenomicDataCommons)
projects <- GenomicDataCommons::projects() %>%
GenomicDataCommons::filter(program.name == "TCGA") %>%
GenomicDataCommons::facet(c("name", "project_id")) %>%
results(size = 100)
results_all()

tcga_project_ids <- projects$project_id
tcga_project_ids_list <- projects$project_id

projects_info <- projects() %>%
GenomicDataCommons::filter(project_id %in% tcga_project_ids) %>%
results_all()

diseases_types <- unique(rapply(projects$disease_type, function(x) head(x, 30)))
diseases_types <- unique(
rapply(projects$disease_type, function(x) head(x, 100))
)

primary_sites <- unique(rapply(projects$primary_site, function(x) head(x, 30)))
primary_sites <- unique(
rapply(projects$primary_site, function(x) head(x, 100))
)

cases_pre_info <- cases() %>%
GenomicDataCommons::filter(project.project_id %in% tcga_project_ids) %>%
Expand All @@ -37,5 +41,7 @@ cases_info <- GenomicDataCommons::cases() %>%

files_info <- GenomicDataCommons::files() %>%
GenomicDataCommons::filter(access == "open") %>%
GenomicDataCommons::facet(c("type", "data_type")) %>%
GenomicDataCommons::facet(
c("type", "data_type", "analysis.workflow_type")
) %>%
aggregations()
1 change: 0 additions & 1 deletion tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ge_manifest <- files() %>%
filter(cases.project.project_id == "TCGA-OV") %>%
filter(type == "gene_expression") %>%
filter(analysis.workflow_type == "STAR - Counts") %>%
filter(analysis.workflow_type == "STAR - Counts") %>%
filter(access == "open") %>%
manifest(size = 5)

Expand Down

0 comments on commit 0794595

Please sign in to comment.