Skip to content

Commit

Permalink
passing R check
Browse files Browse the repository at this point in the history
- passing tests 78% coverage
- cleaning checks but still some notes
  • Loading branch information
jreps committed Jul 10, 2024
1 parent f6b95f9 commit a0ccde7
Show file tree
Hide file tree
Showing 75 changed files with 1,242 additions and 2,324 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: OhdsiShinyModules
Type: Package
Title: Repository of Shiny Modules for OHDSI Result Viewers
Version: 2.1.5.9000
Version: 2.2.0
Author: Jenna Reps
Maintainer: Jenna Reps <[email protected]>
Description: Install this package to access useful shiny modules for building shiny apps to explore results using the OHDSI tools .
Expand Down
5 changes: 2 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ export(datasourcesViewer)
export(estimationHelperFile)
export(estimationServer)
export(estimationViewer)
export(evidenceSynthesisHelperFile)
export(evidenceSynthesisServer)
export(evidenceSynthesisViewer)
export(getEnabledCdReports)
export(getExampleConnectionDetails)
export(getLogoImage)
Expand Down Expand Up @@ -104,3 +101,5 @@ export(reportServer)
export(reportViewer)
export(timeDistributionsView)
export(visitContextView)
importFrom(dplyr,"%>%")
importFrom(rlang,.data)
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
OhdsiShinyModules v2.2.0
========================
- Combined cohort method, sccs and evidence synthesis into one estimation module with shared target and outcome ids
- Characterizations now share the target id
- Updated tests to get them all working
- Cleaned R check (but cohort incidence still has many notes)


OhdsiShinyModules v2.1.5
========================
Fixed bug of orphan concepts report not displaying
Expand Down
4 changes: 2 additions & 2 deletions R/OhdsiShinyModules.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#'
#' @description A selection of shiny modules for exploring standardized OHDSI results
#'
#' @docType package
#' @name OhdsiShinyModules
#' @keywords internal
#' @importFrom dplyr %>%
#' @importFrom rlang .data

"_PACKAGE"
4 changes: 3 additions & 1 deletion R/characterization-dechallengeRechallenge.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ characterizationDechallengeRechallengeViewer <- function(id) {
#' @param id the unique reference id for the module
#' @param connectionHandler the connection to the prediction result database
#' @param resultDatabaseSettings a list containing the characterization result schema, dbms, tablePrefix, databaseTable and cgTablePrefix
#' @param targetId a reactive integer specifying the targetId of interest
#' @param outcomeId a reactive integer specifying the outcomeId of interest
#'
#' @return
#' The server to the Dechallenge Rechallenge module
Expand Down Expand Up @@ -283,7 +285,7 @@ characterizationDechallengeRechallengeServer <- function(
)
)
} else{
showNotification("No fails to display")
shiny::showNotification("No fails to display")
}
}
}
Expand Down
47 changes: 21 additions & 26 deletions R/characterization-incidence.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ custom_age_sort <- function(age_categories) {
return(custom_order)
}

base_breaks <- function(n = 10){
function(x) {
axisTicks(log10(range(x, na.rm = TRUE)), log = TRUE, n = n)
}
}

break_setter = function(n = 5) {
function(lims) {pretty(x = as.numeric(lims), n = n)}
}
Expand Down Expand Up @@ -236,6 +230,10 @@ characterizationIncidenceViewer <- function(id) {
#' @param id the unique reference id for the module
#' @param connectionHandler the connection to the prediction result database
#' @param resultDatabaseSettings a list containing the characterization result schema, dbms, tablePrefix, databaseTable and cgTablePrefix
#' @param parents a list of parent cohorts
#' @param parentIndex an integer specifying the parent index of interest
#' @param outcomes a reactive object specifying the outcomes of interest
#' @param targetIds a reactive vector of integer specifying the targetIds of interest
#'
#' @return
#' The server to the prediction incidence module
Expand All @@ -245,7 +243,7 @@ characterizationIncidenceServer <- function(
id,
connectionHandler,
resultDatabaseSettings,
options, # this gets overwritten in code below - why here?
#options, # this gets overwritten in code below - why here?
parents,
parentIndex, # reactive
outcomes, # reactive
Expand Down Expand Up @@ -648,8 +646,9 @@ characterizationIncidenceServer <- function(
extractedData() %>%
dplyr::relocate("tar", .before = "outcomes") %>%
dplyr::select(-c("targetName", "outcomeName")) %>%
dplyr::rename(targetName = targetCohortName,
outcomeName = outcomeCohortName) %>%
dplyr::rename(targetName = "targetCohortName",
outcomeName = "outcomeCohortName"
) %>%
dplyr::mutate(incidenceProportionP100p = as.numeric(.data$incidenceProportionP100p),
incidenceRateP100py = as.numeric(.data$incidenceRateP100py),
dplyr::across(dplyr::where(is.numeric), round, 4),
Expand Down Expand Up @@ -742,8 +741,8 @@ characterizationIncidenceServer <- function(
ifelse(incidenceRateTarFilter() %in% filteredData()$tar,
plotData <- filteredData() %>%
dplyr::filter(.data$tar %in% incidenceRateTarFilter()) %>%
dplyr::mutate(targetLabel = paste(targetIdShort, " = ", targetName),
outcomeLabel = paste(outcomeIdShort, " = ", outcomeName)
dplyr::mutate(targetLabel = paste(.data$targetIdShort, " = ", .data$targetName),
outcomeLabel = paste(.data$outcomeIdShort, " = ", .data$outcomeName)
),
shiny::validate("Selected TAR is not found in your result data. Revise input selections or select a different TAR.")
)
Expand Down Expand Up @@ -1210,19 +1209,15 @@ characterizationIncidenceServer <- function(

plotData <- plotData %>%
dplyr::filter(#ageGroupName != "Any" &
genderName == "Any" &
startYear == "Any") %>%
dplyr::mutate(targetLabel = paste(targetIdShort, " = ", targetName),
outcomeLabel = paste(outcomeIdShort, " = ", outcomeName),
ageGroupName = factor(ageGroupName, levels = custom_age_sort(ageGroupName), ordered = TRUE)
.data$genderName == "Any" &
.data$startYear == "Any") %>%
dplyr::mutate(targetLabel = paste(.data$targetIdShort, " = ", .data$targetName),
outcomeLabel = paste(.data$outcomeIdShort, " = ", .data$outcomeName),
ageGroupName = factor(.data$ageGroupName, levels = custom_age_sort(.data$ageGroupName), ordered = TRUE)
) %>%
dplyr::rename("Target" = targetIdShort,
"Outcome" = outcomeIdShort,
"Age" = ageGroupName)

# plotHeightStandardAgeSex <- shiny::reactive({
# paste(sum(length(unique(plotData$targetLabel)), length(unique(plotData$Age)), -3)*100, "px", sep="")
# })
dplyr::rename("Target" = "targetIdShort",
"Outcome" = "outcomeIdShort",
"Age" = "ageGroupName")

# Get unique target and outcome labels
unique_target_labels <- strwrap(unique(plotData$targetLabel), width = 300)
Expand All @@ -1241,9 +1236,9 @@ characterizationIncidenceServer <- function(

base_plot <- ggplot2::ggplot(
data = plotData,
ggplot2::aes(x = Age,
y = incidenceRateP100py,
color = cdmSourceAbbreviation
ggplot2::aes(x = .data$Age,
y = .data$incidenceRateP100py,
color = .data$cdmSourceAbbreviation
)
) +
ggplot2::geom_point(
Expand Down
2 changes: 1 addition & 1 deletion R/characterization-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ characterizationServer <- function(
id = 'cohortIncidenceTab',
connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings,
options = options,
#options = options,
parents = parents,
parentIndex = parentIndex, # reactive
outcomes = outcomes, # reactive
Expand Down
21 changes: 7 additions & 14 deletions R/characterization-timeToEvent.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ characterizationTimeToEventViewer <- function(id) {
#' @param id the unique reference id for the module
#' @param connectionHandler the connection to the prediction result database
#' @param resultDatabaseSettings a list containing the characterization result schema, dbms, tablePrefix, databaseTable and cgTablePrefix
#' @param targetId a reactive integer specifying the targetId of interest
#' @param outcomeId a reactive integer specifying the outcomeId of interest
#'
#' @return
#' The server to the prediction time to event module
Expand Down Expand Up @@ -107,9 +109,9 @@ characterizationTimeToEventServer <- function(
) %>%
dplyr::mutate(targetName = options()$targetName,
outcomeName = options()$outcomeName) %>%
dplyr::relocate(databaseName, .before = databaseId) %>%
dplyr::relocate(targetName, .after = databaseName) %>%
dplyr::relocate(outcomeName, .after = targetName)
dplyr::relocate("databaseName", .before = "databaseId") %>%
dplyr::relocate("targetName", .after = "databaseName") %>%
dplyr::relocate("outcomeName", .after = "targetName")
})


Expand Down Expand Up @@ -248,8 +250,8 @@ characterizationTimeToEventServer <- function(
timeToEventData = allData, # reactive
databases = input$databases,
times = input$times,
outcomeType = input$outcomeTypes,
targetOutcomeType = input$targetOutcomeTypes
outcomeTypes = input$outcomeTypes,
targetOutcomeTypes = input$targetOutcomeTypes
)
)

Expand Down Expand Up @@ -355,17 +357,8 @@ plotTimeToEvent <- function(
)
) +
ggplot2::geom_bar(
#position="stacked",
stat = "identity"
) +
#ggplot2::geom_text(
# ggplot2::aes(
# label = .data$numEvents
# ),
# vjust = 1.6,
# color = "white",
# size = 3.5
# ) +
ggplot2::facet_wrap(ncol = nDatabases ,
.data$timeScale ~ .data$databaseName , scales = 'free'
) +
Expand Down
2 changes: 1 addition & 1 deletion R/components-data-viewer.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @param id string
#' @param downloadedFileName string, desired name of downloaded data file. can use the name from the module that is being used
#'
#' @param boxTitle the title added to the box
#' @return shiny module UI
#'
resultTableViewer <- function(
Expand Down
44 changes: 4 additions & 40 deletions R/estimation-cohort-method-covariateBalance.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ cohortMethodCovariateBalanceServer <- function(
selectedRow,
connectionHandler,
resultDatabaseSettings,
metaAnalysisDbIds = NULL) {
metaAnalysisDbIds = NULL
) {

shiny::moduleServer(
id,
Expand All @@ -96,35 +97,6 @@ cohortMethodCovariateBalanceServer <- function(
resultDatabaseSettings
)

# input selection component -- could be added later if desired
# inputSelectedResults <- inputSelectionServer(
# id = "input-selection-results",
# inputSettingList = list(
# createInputSetting(
# rowNumber = 1,
# columnWidth = 12,
# varName = 'covariateAnalysisId',
# uiFunction = 'shinyWidgets::pickerInput',
# updateFunction = 'shinyWidgets::updatePickerInput',
# uiInputs = list(
# label = 'Covariate Analysis Name: ',
# choices = options$covariateAnalysisId,
# selected = options$covariateAnalysisId, #
# multiple = T,
# options = shinyWidgets::pickerOptions(
# actionsBox = TRUE,
# liveSearch = TRUE,
# size = 10,
# liveSearchStyle = "contains",
# liveSearchPlaceholder = "Type here to search",
# virtualScroll = 50
# )
# )
# )
# )
# )


balance <- shiny::reactive({
row <- selectedRow()
if(is.null(row$targetId)){
Expand All @@ -137,9 +109,6 @@ cohortMethodCovariateBalanceServer <- function(
targetId = row$targetId,
comparatorId = row$comparatorId,
databaseId = row$databaseId,
# covariateAnalysisId = ifelse(is.null(inputSelectedResults()$covariateAnalysisId),
# -1,
# inputSelectedResults()$covariateAnalysisId),
analysisId = row$analysisId)},
error = function(e){return(data.frame())}
)
Expand Down Expand Up @@ -299,8 +268,8 @@ cohortMethodCovariateBalanceServer <- function(
dbNames <- getDatabaseName(connectionHandler = connectionHandler,
resultDatabaseSettings = resultDatabaseSettings)
comb <- dplyr::inner_join(balance, dbNames) %>%
dplyr::relocate(cdmSourceAbbreviation, .after = databaseId) %>%
dplyr::select(-c(databaseId))
dplyr::relocate("cdmSourceAbbreviation", .after = "databaseId") %>%
dplyr::select(-c("databaseId"))
}
)

Expand All @@ -322,11 +291,6 @@ cohortMethodCovariateBalanceServer <- function(
resultTableServer(
id = "balanceTable",
df = renderBalanceTable,
# selectedCols = c("cdmSourceAbbreviation", "targetName", "targetIdShort", "outcomeName", "outcomeIdShort",
# "ageGroupName", "genderName", "startYear", "tar", "outcomes",
# "incidenceProportionP100p", "incidenceRateP100py"),
# sortedCols = c("ageGroupName", "genderName", "startYear", "incidenceRateP100py"),
# elementId = "incidence-select",
colDefsInput = cmBalanceColList,
downloadedFileName = "covariateBalanceTable-"
)
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions R/estimation-cohort-method-results.R
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,29 @@ estimationGetCMMetaEstimation <- function(

return(unique(result))
}


# Function to format results
# used by both cm and sccs
computeTraditionalP <- function(
logRr,
seLogRr,
twoSided = TRUE,
upper = TRUE
)
{
z <- logRr/seLogRr

pUpperBound <- 1 - stats::pnorm(z)
pLowerBound <- stats::pnorm(z)

if (twoSided) {
return(2 * pmin(pUpperBound, pLowerBound))
}
else if (upper) {
return(pUpperBound)
}
else {
return(pLowerBound)
}
}
24 changes: 16 additions & 8 deletions R/estimation-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ estimationServer <- function(
)
}
})
# end observed targetId

output$targetSelection <- shiny::renderUI({
shiny::fluidRow(
Expand Down Expand Up @@ -245,7 +246,7 @@ estimationServer <- function(
),
style = 'margin-left: 2%; width: 78%; display: inline-block; vertical-align: middle;'
),
div(
shiny::div(
shiny::actionButton(
inputId = session$ns('targetSelect'),
label = 'Select',
Expand All @@ -257,10 +258,10 @@ estimationServer <- function(
})


targetSelected <- shiny::reactiveVal()
comparatorIds <- shiny::reactiveVal()
targetIds <- shiny::reactiveVal()
outcomeId <- shiny::reactiveVal()
targetSelected <- shiny::reactiveVal(NULL)
comparatorIds <- shiny::reactiveVal(NULL)
targetIds <- shiny::reactiveVal(NULL)
outcomeId <- shiny::reactiveVal(NULL)

shiny::observeEvent(input$targetSelect, {

Expand Down Expand Up @@ -395,10 +396,17 @@ getEstimationTypes <- function(
}

# Evidence Synthesis
if(paste0(
if(
paste0(
resultDatabaseSettings$esTablePrefix,
'result'
) %in% tbls){
'cm_result'
) %in% tbls ||
paste0(
resultDatabaseSettings$esTablePrefix,
'sccs_result'
) %in% tbls

){
results <- c(results, "Evidence Synthesis")
}

Expand Down
Loading

0 comments on commit a0ccde7

Please sign in to comment.