From 05d880ca7fc10e668ba7288dc9b2c2e6c442c080 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Tue, 21 Nov 2023 01:05:11 +0100 Subject: [PATCH 1/7] shiny Alopecia only sunburst --- DESCRIPTION | 9 ++- NAMESPACE | 7 ++ R/runShinyAlopecia.R | 137 ++++++++++++++++++++++++++++++++++++++++ man/runShinyAlopecia.Rd | 11 ++++ 4 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 R/runShinyAlopecia.R create mode 100644 man/runShinyAlopecia.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 76e296c..cc1aa54 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,10 +13,15 @@ Imports: dplyr, magrittr, readr, - TreatmentPatterns (>= 2.6.0), + TreatmentPatterns (>= 2.5.2), CohortDiagnostics, CirceR, - CohortGenerator + CohortGenerator, + shiny, + shinythemes, + shinydashboard, + shinycssloaders, + shinyWidgets Suggests: testthat (>= 3.0.0), here, diff --git a/NAMESPACE b/NAMESPACE index ce85928..e84681d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,10 +2,17 @@ export("%>%") export(createCohorts) +export(runShinyAlopecia) export(runStudy) export(runTreatmentPatterns) import(TreatmentPatterns) import(dplyr) +import(here) +import(shiny) +import(shinyWidgets) +import(shinycssloaders) +import(shinydashboard) +import(shinythemes) importFrom(CirceR,buildCohortQuery) importFrom(CirceR,cohortExpressionFromJson) importFrom(CohortDiagnostics,executeDiagnostics) diff --git a/R/runShinyAlopecia.R b/R/runShinyAlopecia.R new file mode 100644 index 0000000..717d46d --- /dev/null +++ b/R/runShinyAlopecia.R @@ -0,0 +1,137 @@ +#' `runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study. +#' +#' @import shiny shinythemes shinydashboard shinycssloaders shinyWidgets TreatmentPatterns here +#' @importFrom readr read_csv +#' @export +runShinyAlopecia <- function() { + ui <- dashboardPage( + dashboardHeader(title = "Menu"), + dashboardSidebar( + sidebarMenu( + menuItem( + text = "Home", + tabName = "home" + ), + menuItem( + text = "TreatmentPathways", + tabName = "data" + ) + ) + ), + dashboardBody( + tabItems( + tabItem( + tabName = "home", + h4("Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon.") + ), + tabItem( + tabName = "data", + uiOutput("dataTable") + ) + ) + ) + ) + + server <- function(input, output, session) { + ## TreatmentPatterns ---- + resultsPathways <- reactive({ + databases <- list.files(here::here("results"), full.names = TRUE) + resultsPathways <- list() + for (i in seq(1:length(databases))) { + # i <- 1 + targetCohorts <- list.files(databases[i], full.names = TRUE) + targetCohortNumber <- list.files(databases[i]) + for (v in seq(1:length(targetCohorts))) { + # v <- 1 + pathwaysFiles <- list.files(targetCohorts[v], full.names = TRUE) + file_metaData <- pathwaysFiles[stringr::str_detect(pathwaysFiles, "metadata")] + cdm_name <- readr::read_csv(file_metaData, show_col_types = FALSE) %>% + pull(cdmSourceName) + file_TreatmentPathways <- pathwaysFiles[stringr::str_detect(pathwaysFiles, "treatmentPathways")] + resultsPathways <- bind_rows(resultsPathways, readr::read_csv(file_TreatmentPathways, show_col_types = FALSE) %>% + mutate(cdm_name = cdm_name, + targetCohort = targetCohortNumber[v])) + } + } + return(resultsPathways) + }) + + output$dataTable <- renderUI({ + tagList( + pickerInput( + inputId = "dataDatabase", + label = "Data partner", + choices = unique(resultsPathways()$cdm_name), + selected = unique(resultsPathways()$cdm_name)[1], + multiple = FALSE + ), + pickerInput( + inputId = "dataTargetCohort", + label = "Target Cohort", + choices = unique(resultsPathways()$targetCohort), + selected = unique(resultsPathways()$targetCohort)[1], + multiple = FALSE + ), + pickerInput( + inputId = "dataSex", + label = "Sex", + choices = unique(resultsPathways()$sex), + selected = unique(resultsPathways()$sex)[1], + multiple = FALSE + ), + pickerInput( + inputId = "dataAge", + label = "Age", + choices = unique(resultsPathways()$age), + selected = unique(resultsPathways()$age)[1], + multiple = FALSE + ), + pickerInput( + inputId = "dataIndex", + label = "Index year", + choices = unique(resultsPathways()$indexYear), + selected = unique(resultsPathways()$indexYear)[1], + multiple = FALSE + ), + tabsetPanel( + type = "tabs", + tabPanel( + "Data", + DT::dataTableOutput(outputId = "treatmentPathways") + ), + tabPanel( + "Sunburst Plot", + uiOutput(outputId = "sunburstPlot") + ) + # , + # tabPanel( + # "Sankey Diagram", + # uiOutput(outputId = "sankeyDiagram") + # ) + ) + ) + }) + + pathwaysData <- reactive({ + resultsPathways() %>% + filter(cdm_name == input$dataDatabase, + targetCohort == input$dataTargetCohort, + sex == input$dataSex, + age == input$dataAge, + indexYear == input$dataIndex) + }) + + output$treatmentPathways <- DT::renderDataTable(pathwaysData()) + + output$sunburstPlot <- renderUI({ + TreatmentPatterns::createSunburstPlot2(treatmentPathways = pathwaysData(), + groupCombinations = TRUE) + }) + + # output$sankeyDiagram <- renderUI({ + # TreatmentPatterns::createSankeyDiagram2(treatmentPathways = pathwaysData(), + # groupCombinations = TRUE) + # }) + } + shinyApp(ui, server) +} \ No newline at end of file diff --git a/man/runShinyAlopecia.Rd b/man/runShinyAlopecia.Rd new file mode 100644 index 0000000..0af2a71 --- /dev/null +++ b/man/runShinyAlopecia.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/runShiny.R +\name{runShinyAlopecia} +\alias{runShinyAlopecia} +\title{`runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study.} +\usage{ +runShinyAlopecia() +} +\description{ +`runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study. +} From 118f459fbc4ed012ebab8cf5ed8b735548fcb5ad Mon Sep 17 00:00:00 2001 From: "Ross D. Williams" <34747165+rossdwilliams@users.noreply.github.com> Date: Tue, 21 Nov 2023 09:06:52 +0100 Subject: [PATCH 2/7] added Here to description --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 76e296c..85c8c41 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -16,7 +16,8 @@ Imports: TreatmentPatterns (>= 2.6.0), CohortDiagnostics, CirceR, - CohortGenerator + CohortGenerator, + Here Suggests: testthat (>= 3.0.0), here, From a76ce018778a343828ab03ef72c859a119ace94f Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Tue, 21 Nov 2023 09:24:18 +0100 Subject: [PATCH 3/7] resultsFolder --- .gitignore | 5 ++--- R/runShinyAlopecia.R | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8f3679d..8ab0b84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,12 +2,11 @@ .Rhistory .RData .Ruserdata - errorReport* Results/* - .DS_Store CodeToRunSynthea.R CodeToRunSnowflake.R CodeToRunIPCI.R -errorReportSql.txt \ No newline at end of file +errorReportSql.txt +rsconnect diff --git a/R/runShinyAlopecia.R b/R/runShinyAlopecia.R index 717d46d..caaf0f8 100644 --- a/R/runShinyAlopecia.R +++ b/R/runShinyAlopecia.R @@ -3,7 +3,7 @@ #' @import shiny shinythemes shinydashboard shinycssloaders shinyWidgets TreatmentPatterns here #' @importFrom readr read_csv #' @export -runShinyAlopecia <- function() { +runShinyAlopecia <- function(resultsFolder = here::here("results")) { ui <- dashboardPage( dashboardHeader(title = "Menu"), dashboardSidebar( @@ -35,7 +35,7 @@ runShinyAlopecia <- function() { server <- function(input, output, session) { ## TreatmentPatterns ---- resultsPathways <- reactive({ - databases <- list.files(here::here("results"), full.names = TRUE) + databases <- list.files(resultsFolder, full.names = TRUE) resultsPathways <- list() for (i in seq(1:length(databases))) { # i <- 1 From 6e70cf3ee4e6718703098b5bc08477605dfd70a8 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Tue, 21 Nov 2023 09:28:56 +0100 Subject: [PATCH 4/7] DESCRIPTION typo --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 48c0a10..d8c586d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,7 @@ Imports: shinydashboard, shinycssloaders, shinyWidgets - here, + here Suggests: testthat (>= 3.0.0), rmarkdown, From ed84f1344abd8a27f2bb480a1471b7dbcc7005aa Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Tue, 21 Nov 2023 09:48:58 +0100 Subject: [PATCH 5/7] check passing locally --- .Rbuildignore | 1 + DESCRIPTION | 6 ++++-- NAMESPACE | 7 ++++++- R/globals.R | 12 +++++++++++- R/runShinyAlopecia.R | 7 ++++++- man/runShinyAlopecia.Rd | 7 +++++-- 6 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 9affaf0..05f3305 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ ^LICENSE\.md$ ^\.github$ ^README\.Rmd$ +^rsconnect$ diff --git a/DESCRIPTION b/DESCRIPTION index d8c586d..0957c60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,8 +21,10 @@ Imports: shinythemes, shinydashboard, shinycssloaders, - shinyWidgets - here + shinyWidgets, + here, + DT, + stringr Suggests: testthat (>= 3.0.0), rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index e84681d..a641e96 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,6 @@ export(runTreatmentPatterns) import(TreatmentPatterns) import(dplyr) import(here) -import(shiny) import(shinyWidgets) import(shinycssloaders) import(shinydashboard) @@ -20,6 +19,12 @@ importFrom(CohortGenerator,createCohortTables) importFrom(CohortGenerator,generateCohortSet) importFrom(CohortGenerator,getCohortCounts) importFrom(CohortGenerator,getCohortTableNames) +importFrom(DT,dataTableOutput) +importFrom(DT,renderDataTable) importFrom(magrittr,"%>%") importFrom(readr,read_csv) importFrom(readr,write_csv) +importFrom(shiny,h4) +importFrom(shiny,shinyApp) +importFrom(shiny,uiOutput) +importFrom(stringr,str_detect) diff --git a/R/globals.R b/R/globals.R index 1805b4b..03dda6b 100644 --- a/R/globals.R +++ b/R/globals.R @@ -13,4 +13,14 @@ utils::globalVariables(c('sessionInfo', 'cohortSubjects', 'cohortId', 'cohortName', - 'cohortId')) \ No newline at end of file + 'cohortId', + 'age', + 'cdmSourceName', + 'indexYear', + 'sex', + 'targetCohort', + 'reactive', + 'renderUI', + 'tabPanel', + 'tagList', + 'tabsetPanel')) \ No newline at end of file diff --git a/R/runShinyAlopecia.R b/R/runShinyAlopecia.R index caaf0f8..d4c5b05 100644 --- a/R/runShinyAlopecia.R +++ b/R/runShinyAlopecia.R @@ -1,7 +1,12 @@ #' `runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study. #' -#' @import shiny shinythemes shinydashboard shinycssloaders shinyWidgets TreatmentPatterns here +#' @param resultsFolder Define the results folder path in character. +#' +#' @import shinythemes shinydashboard shinycssloaders shinyWidgets TreatmentPatterns here #' @importFrom readr read_csv +#' @importFrom DT dataTableOutput renderDataTable +#' @importFrom stringr str_detect +#' @importFrom shiny shinyApp h4 uiOutput #' @export runShinyAlopecia <- function(resultsFolder = here::here("results")) { ui <- dashboardPage( diff --git a/man/runShinyAlopecia.Rd b/man/runShinyAlopecia.Rd index 0af2a71..b12a5ae 100644 --- a/man/runShinyAlopecia.Rd +++ b/man/runShinyAlopecia.Rd @@ -1,10 +1,13 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/runShiny.R +% Please edit documentation in R/runShinyAlopecia.R \name{runShinyAlopecia} \alias{runShinyAlopecia} \title{`runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study.} \usage{ -runShinyAlopecia() +runShinyAlopecia(resultsFolder = here::here("results")) +} +\arguments{ +\item{resultsFolder}{Define the results folder path in character.} } \description{ `runAlopeciaShiny()` launches an app to visualise TreatmentPatterns results for the alopecia study. From b98757043b8ea2c3a3757ddbabb4451a6eebd4d6 Mon Sep 17 00:00:00 2001 From: Cesar Barboza Date: Tue, 21 Nov 2023 11:00:22 +0100 Subject: [PATCH 6/7] fix between 101 --- R/runStudy.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/runStudy.R b/R/runStudy.R index 2bb31df..bea5239 100644 --- a/R/runStudy.R +++ b/R/runStudy.R @@ -70,7 +70,7 @@ runStudy <- function(connectionDetails, targetCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% filter(cohortId <= 100) eventCohorts <- readr::read_csv(file.path(outputFolder, "cohortsGenerated.csv")) %>% - filter(between(cohortId, 100, 114)) + filter(between(cohortId, 101, 114)) for (i in seq(1:length(targetCohorts$cohortId))) { outputSubDir <- file.path(outputFolder, 'treatmentPatterns', targetCohorts[i,]$cohortId) if (!dir.exists(outputSubDir)) { From d99fafe80f77f5455ff008488e9df72ec68deb90 Mon Sep 17 00:00:00 2001 From: "Ross D. Williams" <34747165+rossdwilliams@users.noreply.github.com> Date: Tue, 21 Nov 2023 11:13:00 +0100 Subject: [PATCH 7/7] Update DESCRIPTION --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0957c60..9aea717 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: EhdenAlopecia Title: Analytic software to perform large-scale distributed analysis of patients with Alopecia as part of the EHDEN study-athon -Version: 1.1.1 +Version: 1.2.1 Authors@R: person("Ross", "Williams", , "r.williams@derasmusmc.nl", role = c("aut", "cre")) Description: This package creates the cohorts for this EHDEN Alopecia study study. Based on this cohort diagnostics, incidence and prevalence rates and treatment patterns are analysis are performed. License: Apache License (>= 2)