cmu-delphi / cmu-delphi/forecast-eval
Consider making `plotly` plot directly instead of converting from `ggplot` plot
- Dominant language
- R
- Stars
- 6
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
There's some indication that `plotly` plots are faster to generate than making a `ggplot2` plot and converting to `plotly`. Since plot creation and rendering is a slow part of the dashboard, meaning this switch could be a good way to provide overall speedups to the dashboard.
Most of the work has already been done on the [`ndefries/use-plotly-directly` branch](https://github.com/cmu-delphi/forecast-eval/tree/ndefries/use-plotly-directly). Remaining tasks to match behavior of current dashboard:
- Add gray rectangle between faceted plots to display horizon info. Formatting info for rectangles and horizon labels:
```
# Horizon rectangles
str(finalPlot$x$layout$shapes, max.level = 2)
List of 4
$ :List of 9
..$ type : chr "rect"
..$ fillcolor: chr "transparent"
$ line :List of 3
..$ color : chr "rgba(51,51,51,1)"
..$ width : num 0.664
..$ linetype: chr "solid"
..$ yref : chr "paper"
..$ xref : chr "paper"
..$ x0 : num 0
..$ x1 : num 1
..$ y0 : num 0.514
..$ y1 : num 1
$ :List of 11
..$ type : chr "rect"
..$ fillcolor: chr "rgba(217,217,217,1)"
..$ line :List of 3
..$ yref : chr "paper"
..$ xref : chr "paper"
..$ x0 : num 0
..$ x1 : num 1
..$ y0 : num 0
..$ y1 : num 23.4
..$ yanchor : num 1
..$ ysizemode: chr "pixel"
# Horizon labels
> str(finalPlot$x$layout$annotations, max.level = 2)
$ :List of 12
..$ text : chr "Horizon: 2 Week(s)"
..$ x : num 0.5
..$ y : num 0.486
..$ showarrow: logi FALSE
..$ ax : num 0
..$ ay : num 0
..$ font :List of 3
..$ xref : chr "paper"
..$ yref : chr "paper"
..$ textangle: num 0
..$ xanchor : chr "center"
..$ yanchor : chr "bottom"
```
- Add "drag to zoom" text as separate annotation? might scale better with page size changes
- [Add horizontal reference line](https://github.com/cmu-delphi/forecast-eval/blob/d0cec65fdc1d5654496d8b10982e51300ae79cb0/app/server.R#L459) for coverage plots
- Setting x-axis limits depending on the as-of date selection and whether forecast values are displayed on the truth plot. `plotly` doesn't [let an axis limit float if passed an `NA`](https://github.com/cmu-delphi/forecast-eval/blob/381814483b6aa6a7e7f0b1bc97766d83561c65b7/app/server.R#L433-L439), so we'd probably need to define a separate function to calculate min/max x limits based on data range.
- Make y-axis ranges match across subplots
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by comparing the ndefries/use-plotly-directly branch with the current dashboard, using the referenced sections of app/server.R for the coverage line and x-axis behavior. Done means matching current dashboard behavior for horizon rectangles and labels, drag-to-zoom text, coverage reference lines, x-axis limits, and y-axis ranges while using direct plotly generation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, r
- Domain
- data-visualization, performance
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100