Skip to content

Commit 3818144

Browse files
authored
Merge pull request #270 from cmu-delphi/ndefries/show-us-coverage-plot
When changing score to/from coverage, show main plot and make sure truth data is relevant
2 parents 5178747 + 9e0a263 commit 3818144

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

app/global.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ HOSPITALIZATIONS_TARGET_DAY <- "Wednesday"
1818
TOTAL_LOCATIONS <- "Totaled Over States*"
1919
AHEAD_OPTIONS <- c(1, 2, 3, 4)
2020

21+
INIT_SCORE_TYPE <- "wis"
2122
INIT_TARGET <- "Hospitalizations"
2223
TARGET_OPTIONS <- c("Deaths", "Cases", "Hospitalizations")
2324

app/server.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ server <- function(input, output, session) {
129129
CASES_DEATHS_CURRENT <- resolveCurrentCasesDeathDay()
130130
HOSP_CURRENT <- resolveCurrentHospDay()
131131

132-
# Set the "previous" target to be the same as the starting target variable
132+
# Set the "previous" target and score type to be the same as the starting values
133133
PREV_TARGET <- INIT_TARGET
134+
PREV_SCORE_TYPE <- INIT_SCORE_TYPE
134135

135136
PREV_AS_OF_DATA <- reactiveVal(NULL)
136137
AS_OF_CHOICES <- reactiveVal(HOSP_CURRENT)
@@ -264,7 +265,7 @@ server <- function(input, output, session) {
264265
output[[paste0("renderWarningText", DASH_SUFFIX)]] <- renderText("")
265266
showElement(paste0("truthPlot", DASH_SUFFIX))
266267
}
267-
# Not totaling over all locations
268+
# Not totaling over all locations (single states and "US")
268269
} else {
269270
if (!is.null(asOfData)) {
270271
filteredScoreDf <- filteredScoreDf %>%
@@ -788,14 +789,28 @@ server <- function(input, output, session) {
788789
# Only show forecasters that have data for the score chosen
789790
updateForecasterChoices(session, df, input$forecasters, input$scoreType)
790791

791-
# If we are switching between coverage and other score types we need to
792-
# update the as of data we have so it matches the correct locations shown
793-
if (input$location == "US") {
792+
showScoreExplanation(session, input$scoreType, DASH_SUFFIX)
793+
USE_CURR_TRUTH <<- TRUE
794+
795+
# Normally when score type selection changes, we reuse the existing truth
796+
# plot (behavior is toggled by `USE_CURR_TRUTH`). This is valid as long
797+
# as the locations reported by each score type are the same.
798+
#
799+
# However, regardless of which location is selected, coverage aggregates
800+
# scores over states that have forecasts reported by all selected
801+
# forecasters. This means that when changing to or from "coverage" and
802+
# any single state or "US" is selected as the location (that is, we are
803+
# not aggregating over shared locations), we need to regenerate the truth
804+
# plot with updated truth data.
805+
if ((input$scoreType == "coverage" || PREV_SCORE_TYPE == "coverage") && input$location != TOTAL_LOCATIONS) {
794806
updateAsOfData()
807+
# Don't ONLY create a new truth plot, make a new main plot, too.
808+
RE_RENDER_TRUTH <<- FALSE
809+
# Need to create new truth plot.
810+
USE_CURR_TRUTH <<- FALSE
795811
}
796812

797-
showScoreExplanation(session, input$scoreType, DASH_SUFFIX)
798-
USE_CURR_TRUTH <<- TRUE
813+
PREV_SCORE_TYPE <<- input$scoreType
799814
})
800815

801816
# When forecaster selections change, update available aheads, locations, and CIs to choose from

app/ui.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ sidebar <- tags$div(
6767
"Spread" = "sharpness",
6868
"Absolute Error" = "ae",
6969
"Coverage" = "coverage"
70-
)
70+
),
71+
selected = INIT_SCORE_TYPE
7172
),
7273
conditionalPanel(
7374
condition = "input.scoreType != 'coverage'",

0 commit comments

Comments
 (0)