@@ -128,31 +128,31 @@ server <- function(input, output, session) {
128
128
}
129
129
# Need to do this after setting dfWithForecasts to leave in aheads for forecasts
130
130
filteredScoreDf <- filteredScoreDf %> % filter(ahead %in% input $ aheads )
131
- if (dim (filteredScoreDf )[ 1 ] == 0 ) {
131
+ if (nrow (filteredScoreDf ) == 0 ) {
132
132
output $ renderWarningText <- renderText(paste0(
133
133
" The selected forecasters do not have enough data " ,
134
134
" to display the selected scoring metric."
135
135
))
136
136
return ()
137
137
}
138
138
if (is.null(asOfData )) {
139
- if (! is.null(isolate(PREV_AS_OF_DATA())) && dim (isolate(PREV_AS_OF_DATA()))[ 1 ] != 0 &&
139
+ if (! is.null(isolate(PREV_AS_OF_DATA())) && nrow (isolate(PREV_AS_OF_DATA())) != 0 &&
140
140
isolate(input $ asOf ) != " " && isolate(input $ asOf ) != isolate(CURRENT_WEEK_END_DATE())) {
141
141
asOfData <- isolate(PREV_AS_OF_DATA())
142
142
}
143
143
}
144
- if (! is.null(asOfData ) && dim (asOfData )[ 1 ] != 0 ) {
144
+ if (! is.null(asOfData ) && nrow (asOfData ) != 0 ) {
145
145
asOfData <- asOfData %> % rename(target_end_date = time_value , as_of_actual = value )
146
146
asOfData <- asOfData [c(" target_end_date" , " geo_value" , " as_of_actual" )]
147
147
148
148
# Get the 'as of' dates that are the target_end_dates in the scoring df
149
149
dateGroupDf <- asOfData %> % filter(asOfData $ target_end_date %in% filteredScoreDf $ target_end_date )
150
- if (dim (dateGroupDf )[ 1 ] != 0 ) {
150
+ if (nrow (dateGroupDf ) != 0 ) {
151
151
# Since cases and deaths are shown as weekly incidence, but the "as of" data from the covidcast API
152
152
# is daily, we need to sum over the days leading up to the target_end_date of each week to get the
153
153
# weekly incidence
154
154
asOfData <- filterAsOfData(asOfData , dateGroupDf , filteredScoreDf )
155
- filteredScoreDf <- merge (filteredScoreDf , asOfData , by = c(" target_end_date" , " geo_value" ), all = TRUE )
155
+ filteredScoreDf <- full_join (filteredScoreDf , asOfData , by = c(" target_end_date" , " geo_value" ))
156
156
} else {
157
157
# Input 'as of' date chosen does not match the available target_end_dates that result from the rest of the selected inputs
158
158
# It is too far back or we are switching between hosp and cases/deaths which have different target date days
@@ -249,9 +249,10 @@ server <- function(input, output, session) {
249
249
updateAsOfChoices(session , truthDf )
250
250
251
251
# Format and transform data for plot
252
- filteredScoreDf <- filteredScoreDf %> % filter(! is.na(Week_End_Date ))
253
- filteredScoreDf <- filteredScoreDf [c(" Forecaster" , " Forecast_Date" , " Week_End_Date" , " Score" , " ahead" )]
254
- filteredScoreDf <- filteredScoreDf %> % mutate(across(where(is.numeric ), ~ round(. , 2 )))
252
+ filteredScoreDf <- filteredScoreDf %> %
253
+ filter(! is.na(Week_End_Date )) %> %
254
+ select(Forecaster , Forecast_Date , Week_End_Date , Score , ahead ) %> %
255
+ mutate(across(where(is.numeric ), ~ round(. , 2 )))
255
256
if (input $ scoreType != " coverage" ) {
256
257
if (input $ scaleByBaseline ) {
257
258
baselineDf <- filteredScoreDf %> % filter(Forecaster %in% " COVIDhub-baseline" )
@@ -328,12 +329,10 @@ server <- function(input, output, session) {
328
329
}
329
330
plotHeight <- 550 + (length(input $ aheads ) - 1 ) * 100
330
331
finalPlot <-
331
- ggplotly(p , tooltip = c(" x" , " y" , " shape" , " label" )) %> %
332
+ ggplotly(p , tooltip = c(" x" , " y" , " shape" , " label" ), height = plotHeight ) %> %
332
333
layout(
333
- height = plotHeight ,
334
334
legend = list (orientation = " h" , y = - 0.1 ),
335
335
margin = list (t = 90 ),
336
- height = 500 ,
337
336
hovermode = " x unified" ,
338
337
xaxis = list (
339
338
title = list (text = " Target Date" , standoff = 8L ),
@@ -389,7 +388,7 @@ server <- function(input, output, session) {
389
388
geom_point(aes(y = Reported_As_Of_Incidence , color = " Reported_As_Of_Incidence" ))
390
389
if (input $ showForecasts ) {
391
390
finalPlot <- finalPlot +
392
- geom_line(aes(y = Quantile_50 , color = Forecaster , shape = Forecaster )) +
391
+ geom_line(aes(y = Quantile_50 , color = Forecaster )) +
393
392
geom_point(aes(y = Quantile_50 , color = Forecaster , shape = Forecaster ))
394
393
}
395
394
} else {
@@ -460,12 +459,13 @@ server <- function(input, output, session) {
460
459
# Create a df to fill in the corresponding target_end_date in a new date_group column for all intervening days
461
460
dateGroupDf [, " date_group" ] <- NA
462
461
dateGroupDf $ date_group <- dateGroupDf $ target_end_date
463
- asOfData <- merge (asOfData , dateGroupDf , by = c(" target_end_date" , " geo_value" , " as_of_actual" ), all = TRUE )
462
+ asOfData <- full_join (asOfData , dateGroupDf , by = c(" target_end_date" , " geo_value" , " as_of_actual" ))
464
463
465
464
# Cut off the extra days on beginning and end of series so that when we sum the values we are only
466
465
# summing over the weeks included in the score plot
467
- asOfData <- asOfData %> % filter(target_end_date > = min(filteredScoreDf $ target_end_date ) - 6 )
468
- asOfData <- asOfData %> % filter(target_end_date < = isolate(input $ asOf ))
466
+ asOfData <- asOfData %> %
467
+ filter(target_end_date > = min(filteredScoreDf $ target_end_date ) - 6 ) %> %
468
+ filter(target_end_date < = isolate(input $ asOf ))
469
469
470
470
# Fill in the date_group column with the target week end days for all intervening days
471
471
asOfData <- asOfData %> %
@@ -688,8 +688,8 @@ server <- function(input, output, session) {
688
688
# Ensure there is always one forecaster selected
689
689
if (length(input $ forecasters ) < 1 ) {
690
690
updateSelectInput(session , " forecasters" ,
691
- selected = c(" COVIDhub-ensemble " )
692
- ) # Use ensemble rather than baseline bc it has hospitalization scores
691
+ selected = c(" COVIDhub-baseline " )
692
+ )
693
693
}
694
694
# Ensure COVIDhub-baseline is selected when scaling by baseline
695
695
if (input $ scaleByBaseline && ! (" COVIDhub-baseline" %in% input $ forecasters )) {
@@ -745,7 +745,7 @@ server <- function(input, output, session) {
745
745
hideElement(" truth-plot-loading-message" )
746
746
PREV_AS_OF_DATA(asOfTruthData )
747
747
748
- if (dim (asOfTruthData )[ 1 ] == 0 ) {
748
+ if (nrow (asOfTruthData ) == 0 ) {
749
749
return ()
750
750
}
751
751
summaryPlot(reRenderTruth = TRUE , asOfData = asOfTruthData )
0 commit comments