Skip to content

Instantly share code, notes, and snippets.

@MarkEdmondson1234
Last active May 31, 2017 08:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save MarkEdmondson1234/b49c43abf9dbf98fb1a9 to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/b49c43abf9dbf98fb1a9 to your computer and use it in GitHub Desktop.
An example of rendering a Dygraph plot in Shiny
## in server.r
output$null_plot <- renderDygraph({
## don't output anything unless you have the data ready
validate(
need(casualImpactData(), "Model Working")
)
## the data for the plot is in here
ci <- casualImpactData()$series
## get the start and end from the user input in ui.r
start <- input$range_date[1]
end <- input$range_date[2]
## we need to convert the dataframe into a timeseries for dygraph
orderme <- seq(as.Date(start), as.Date(end), by=1)
ci <- xts(ci, orderme)
## the dygraph output
dygraph(data=ci[,c('response', 'point.pred', 'point.pred.lower', 'point.pred.upper')],
main="Expected (95% confidence level) vs Observed", group="ci") %>%
dyRangeSelector(dateWindow = c(input$event_date - 7, input$range_date[2])) %>%
dyEvent(date = input$event_date, "Event") %>%
dySeries(c('point.pred.lower', 'point.pred','point.pred.upper'), label='Expected') %>%
dySeries('response', label="Observed")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment