signaturescience / focustools

Forecasting COVID-19 in the US
https://signaturescience.github.io/focustools/
GNU General Public License v3.0
0 stars 0 forks source link

shiny app to visualize forecast output #22

Closed vpnagraj closed 3 years ago

vpnagraj commented 3 years ago

now that we have a method for submitting forecasts manually, we should think about developing a simple shiny app to help us visualize forecast output

the app could live in the focustools package and be launched from the a wrapper function in the package such that we could use the app to interactively explore results locally or view results in a hosted, shiny server context

some initial musings:

stephenturner commented 3 years ago

if hosted somewhere, how does the forecast data get into the app? upload a csv file? put in an S3 bucket?

Could it pull from the submissions folder on this repo? We'd probably have to make it public to do so easily.

vpnagraj commented 3 years ago

LOTS of progress here. see https://github.com/signaturescience/focustools/commit/12b6d31d05c89cd72948b213483ed3bf912f0f10

the app is pretty much good to go ... aesthetics / usability edits not withstanding.

basic structure is that the app file (app.R) lives in pkg inst dir. then we have a wrapper function called focus_explorer() that wraps shiny::runApp and also allows us to pass some args for data to attach to the global environment (which the shiny session can see natively)

point is ... this will work as way for us to interactively look at forecasts locally and/or as the app that we could host on AWS. same code ... and no shiny server necessary :)

if you want you can pull the branch, build, and give it a shot (from root of focustools directory):

library(focustools)
library(tidyverse)

## Get national data
national <- inner_join(
  get_cases( source="jhu", granularity="national"),
  get_deaths(source="jhu", granularity="national"),
  by = c("location", "epiyear", "epiweek"))
## Get state data
state <- inner_join(
  get_cases( source="jhu", granularity="state"),
  get_deaths(source="jhu", granularity="state"),
  by = c("location", "epiyear", "epiweek"))
## combine US and state data
usafull <-
  bind_rows(national, state) %>%
  filter(location %in% c("US", stringr::str_pad(1:56, width=2, pad="0"))) %>%
  make_tsibble() %>%
  filter(monday>"2020-03-01")

focus_explorer(.data = usafull, 
               submission_dir = here::here("submission", "SigSci-TS"),
               port = 3838,
               launch.browser = TRUE)
vpnagraj commented 3 years ago
Screen Shot 2021-02-12 at 3 33 24 PM
stephenturner commented 3 years ago

Nice, got it working.

Will it be computationally burdensome to the app to have all locations selected by default, then allow to deselect before downloading?

I see you're using plot_forecast, which I'd hoped to clean up in #39 so we don't get the cum case plot taking up real estate. If removing 51 panels would speed things up perhaps we should.

image

vpnagraj commented 3 years ago

yeah thats exactly why i didnt have all selected by default. certainly could but it will be slow to load ...

i think removing the ccases would help.

see https://github.com/signaturescience/focustools/issues/45

vpnagraj commented 3 years ago

first version of the app is working.

code merged in #46

going to close this issue and open up more targeted issues for specific tasks as needed.

stephenturner commented 3 years ago

Hmm... if I manually set .GlobalEnv$.submission_dir to the submission dir, and same with data, and directly run app.R, it seems to work for me...

image

But getting another Error: Specified location is not in recorded data - possibly because all the boxes are checked for 52 locations but don't have data in these? Perhaps you want to uncheck those where data doesn't exist (or remove from the sidebar altogether?

image

vpnagraj commented 3 years ago

hmmm.

i wrote the "select location" options as a renderUI. meaning the choices are data driven by the actual submission file. you shouldnt see any locations that are not in the original submission csv file.

are you still able to view the table and summary tabs? i have a hunch that this is an issue with plot_forecast() . i've seen this when i accidentally passed the wrong .data argument (i.e. only US data to plot a forecast that had US and states)

what is your .data argument when you run focus_explorer()?

library(focustools)
library(tidyverse)

## Get national data
national <- inner_join(
  get_cases( source="jhu", granularity="national"),
  get_deaths(source="jhu", granularity="national"),
  by = c("location", "epiyear", "epiweek"))
## Get state data
state <- inner_join(
  get_cases( source="jhu", granularity="state"),
  get_deaths(source="jhu", granularity="state"),
  by = c("location", "epiyear", "epiweek"))
## combine US and state data
usafull <-
  bind_rows(national, state) %>%
  filter(location %in% c("US", stringr::str_pad(1:56, width=2, pad="0"))) %>%
  make_tsibble() %>%
  filter(monday>"2020-03-01")

focus_explorer(.data = usafull, 
               submission_dir = here::here("submission", "SigSci-TS"),
               port = 3838,
               launch.browser = TRUE)
stephenturner commented 3 years ago

Not sure what I was doing yesterday that caused this failure. It's working fine this morning. I'd mixed vocabulary when I was looking at this yesterday - I meant to say there might be forecasts that were checked that didn't actually have a forecast, but that's not the case. Anyway, I'm closing this because none of this is an issue any longer.

stephenturner commented 3 years ago

On second thought, reopen to address mismatch for location names in sidebar versus location FIPS code in plots? Or is this more of a thing that should be addressed directly in #39 ?

vpnagraj commented 3 years ago

the latter. not a shiny app feature. totally a plot_forecast() thing. on it.