Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding phevaluator module functionality and colDefs for all reactables per new result model spec #209

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
191 changes: 103 additions & 88 deletions R/characterization-incidence.R

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions R/cohort-generator-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ cohortGeneratorServer <- function(
error = function(e){
shiny::showNotification(
paste0(
'Error: ',
"Please select at least one column to display"
"Loading..."
)
);
return(NULL)
Expand Down
80 changes: 67 additions & 13 deletions R/phevaluator-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
resultTableViewer(ns("modelCovariatesTable"),
downloadedFileName = "modelCovariatesTable-")
),
shiny::tabPanel(
title = "Model Covariate Summary",
resultTableViewer(ns("modelCovariateSummaryTable"),
downloadedFileName = "modelCovariateSummaryTable-")

Check warning on line 97 in R/phevaluator-main.R

View check run for this annotation

Codecov / codecov/patch

R/phevaluator-main.R#L94-L97

Added lines #L94 - L97 were not covered by tests
),
shiny::tabPanel(
title = "Model Performance",
resultTableViewer(ns("modelPerformanceTable"),
Expand Down Expand Up @@ -233,8 +238,9 @@
resultDatabaseSettings = resultDatabaseSettings
) %>%
dplyr::filter(.data$databaseId %in% input$selectedDatabaseIds &
.data$phenotype %in% input$selectedPhenotypes) %>%
dplyr::select("databaseId":"cohortId", "description", "sensitivity95Ci":"analysisId")
.data$phenotype %in% input$selectedPhenotypes)
# %>%
# dplyr::select("databaseId":"cohortId", "description", "sensitivity95Ci":"analysisId")
}
)

Expand All @@ -250,8 +256,8 @@
connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings
) %>%
dplyr::mutate(buttonSQL = makeButtonLabel("SQL"),
buttonJSON = makeButtonLabel("JSON")) %>%
#dplyr::mutate(buttonSQL = makeButtonLabel("SQL"),
# buttonJSON = makeButtonLabel("JSON")) %>%
dplyr::filter(.data$phenotype %in% input$selectedPhenotypes)
}
)
Expand Down Expand Up @@ -294,6 +300,25 @@
}
)

dataModelCovarSummary <- shiny::eventReactive(
eventExpr = input$generate,
{
if (is.null(input$selectedDatabaseIds) |
is.null(input$selectedPhenotypes)) {
data.frame()
}

getPhevalModelCovarSummary(
connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings
) %>%
dplyr::filter(
.data$databaseId %in% input$selectedDatabaseIds &
.data$phenotype %in% input$selectedPhenotypes
)
}
)

dataModelCovars <- shiny::eventReactive(
eventExpr = input$generate,
{
Expand Down Expand Up @@ -449,47 +474,52 @@
customColDefs <- utils::modifyList(phevalColList, buttonColDefs)


resultTableServer(id = ns("algorithmPerformanceResultsTable"),
resultTableServer(id = "algorithmPerformanceResultsTable",
df = dataAlgorithmPerformance,
colDefsInput = customColDefs,
downloadedFileName = "algorithmPerformanceResultsTable-")

resultTableServer(id = ns("cohortDefinitionSetTable"),
resultTableServer(id = "cohortDefinitionSetTable",
df = dataCohortDefinitionSet,
colDefsInput = customColDefs,
downloadedFileName = "cohortDefinitionSetTable-")

resultTableServer(id = ns("diagnosticsTable"),
resultTableServer(id = "diagnosticsTable",
df = dataDiagnostics,
colDefsInput = customColDefs,
downloadedFileName = "diagnosticsTable-")

resultTableServer(id = ns("evaluationInputParametersTable"),
resultTableServer(id = "evaluationInputParametersTable",
df = dataEvalInputParams,
colDefsInput = customColDefs,
downloadedFileName = "evaluationInputParametersTable-")

resultTableServer(id = ns("modelCovariatesTable"),
resultTableServer(id = "modelCovariateSummaryTable",
df = dataModelCovarSummary,
colDefsInput = customColDefs,
downloadedFileName = "modelCovariateSummaryTable-")

resultTableServer(id = "modelCovariatesTable",
df = dataModelCovars,
colDefsInput = customColDefs,
downloadedFileName = "modelCovariatesTable-")

resultTableServer(id = ns("modelInputParametersTable"),
resultTableServer(id = "modelInputParametersTable",
df = dataModelInputParams,
colDefsInput = customColDefs,
downloadedFileName = "modelInputParametersTable-")

resultTableServer(id = ns("modelPerformanceTable"),
resultTableServer(id = "modelPerformanceTable",
df = dataModelPerformance,
colDefsInput = customColDefs,
downloadedFileName = "modelPerformanceTable-")

resultTableServer(id = ns("testSubjectsTable"),
resultTableServer(id = "testSubjectsTable",
df = dataTestSubjects,
colDefsInput = customColDefs,
downloadedFileName = "testSubjectsTable-")

resultTableServer(id = ns("testSubjectsCovariatesTable"),
resultTableServer(id = "testSubjectsCovariatesTable",
df = dataTestSubjectsCovars,
colDefsInput = customColDefs,
downloadedFileName = "testSubjectsCovariatesTable-")
Expand Down Expand Up @@ -603,6 +633,30 @@
)
}

getPhevalModelCovarSummary <- function(
connectionHandler,
resultDatabaseSettings
) {

sql <- "SELECT * FROM @schema.@pv_table_prefixMODEL_COVARIATE_SUMMARY
;"

df <- connectionHandler$queryDb(
sql = sql,
schema = resultDatabaseSettings$schema,
pv_table_prefix = resultDatabaseSettings$pvTablePrefix
)

df$databaseId = stringi::stri_trans_general(df$databaseId, "latin-ascii")
df$phenotype = stringi::stri_trans_general(df$phenotype, "latin-ascii")
df$analysisName = stringi::stri_trans_general(df$analysisName, "latin-ascii")
df$covariateName = stringi::stri_trans_general(df$covariateName, "latin-ascii")

Check warning on line 653 in R/phevaluator-main.R

View check run for this annotation

Codecov / codecov/patch

R/phevaluator-main.R#L650-L653

Added lines #L650 - L653 were not covered by tests

return(
df

Check warning on line 656 in R/phevaluator-main.R

View check run for this annotation

Codecov / codecov/patch

R/phevaluator-main.R#L655-L656

Added lines #L655 - L656 were not covered by tests
)
}

# d <- getPhevalModelCovars(connectionHandler = connectionHandler,
# resultsSchema = resultDatabaseDetails$schema,
# tablePrefix = resultDatabaseDetails$tablePrefix,
Expand Down
9 changes: 9 additions & 0 deletions extras/codeToCreatePhevaluatorDatabase.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ DatabaseConnector::insertTable(
camelCaseToSnakeCase = F
)

DatabaseConnector::insertTable(
connection = connectionPV,
databaseSchema = 'main',
tableName = 'PV_MODEL_COVARIATE_SUMMARY',
data = read.csv(file.path(resultsPV, "pv_model_covariate_summary.csv")),
createTable = T, dropTableIfExists = T,
camelCaseToSnakeCase = F
)

DatabaseConnector::insertTable(
connection = connectionPV,
databaseSchema = 'main',
Expand Down
Loading
Loading