-
-
Save cocomice/d24597170f39ad13e9a637393d7f6a41 to your computer and use it in GitHub Desktop.
An example of rendering a Dygraph plot in Shiny
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 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