-
Notifications
You must be signed in to change notification settings - Fork 3
add a simpel export button to download the current data frame #126
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
COVERAGE_INTERVALS = c("10", "20", "30", "40", "50", "60", "70", "80", "90", "95", "98") | ||
DEATH_FILTER = "deaths_incidence_num" | ||
CASE_FILTER = "confirmed_incidence_num" | ||
TOTAL_LOCATIONS = "Totaled Over States*" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
source('./common.R') | ||
|
||
create_export_df = function(scoreDf, targetVariable, forecasters, horizon, loc) { | ||
signalFilter = CASE_FILTER | ||
if (targetVariable == "Deaths") { | ||
signalFilter = DEATH_FILTER | ||
} | ||
scoreDf = scoreDf %>% | ||
filter(signal == signalFilter) %>% | ||
filter(ahead %in% horizon) %>% | ||
filter(forecaster %in% forecasters) | ||
if (loc != TOTAL_LOCATIONS) { | ||
scoreDf = scoreDf %>% filter(geo_value == tolower(loc)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should include somewhere what locations are included when the user has selected total locations (not all of the locations are included - it is based on what forecasters are selected and which locations they have in common). But maybe that is not necessary... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how is this information currently shown in the user interface? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
return(scoreDf) | ||
} | ||
|
||
export_scores_ui = div( | ||
downloadButton("exportScores", "Download CSV") | ||
) | ||
|
||
export_scores_server = function(input, output, df) { | ||
output$exportScores <- downloadHandler( | ||
filename = function() { | ||
filename = paste0("forecast-eval-scores-", input$targetVariable) | ||
if (input$location != TOTAL_LOCATIONS) { | ||
filename = paste0(filename, '-', input$location) | ||
} | ||
paste0(filename,'-', Sys.Date(), ".csv") | ||
}, | ||
contentType = 'text/csv', | ||
content = function(file) { | ||
withProgress(message = 'Preparing export', | ||
detail = 'This may take a while...', value = 0, max = 2, { | ||
out_df = create_export_df(df, input$targetVariable, input$forecasters, input$aheads, input$location) | ||
incProgress(1) | ||
write.csv(out_df, file, row.names=FALSE) | ||
incProgress(2) | ||
}) | ||
} | ||
) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that if loc == TOTAL_LOCATIONS, this download actually includes all locations. The downloaded file (with just the initial selections on app load selected) included AS, although it technically shouldn't since the baseline nor ensemble forecasters have data for that. It also technically shouldn't include the US, since that is not included in the plot either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is probably a cleaner way of doing it, but this is what I did in the app to find and reduce by the locations that all forecasters have data for:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also now that I am adding hospitalizations which require even more data preprocessing (because of the difference in how the aheads work) this export function will probably need even more adjustments and require more decisions of what we actually want to show (the raw data vs the processed/filtered data that is shown in the plot). I can bring this up in our next meeting to get thoughts on what we want users to download.