Skip to content

Instantly share code, notes, and snippets.

@MarkEdmondson1234
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkEdmondson1234/9d020cabf5338f3df93f to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/9d020cabf5338f3df93f to your computer and use it in GitHub Desktop.
CausalImpact in Shiny
## in server.r of a shiny app
casualImpactData <- reactive({
## only if we have the data ready
validate(
need(chartData(), "Need data")
)
data <- chartData()
## from user input in ui.r
start <- input$range_date[1]
end <- input$range_date[2]
event <- input$event_date
season <- as.numeric(input$season)
## setting up the necessary data for CausalImpact
pre.period <- as.Date(c(start, event))
post.period <- as.Date(c(event + 1, end))
## doing the CausalImpact call and creating the model data
CausalImpact(data, pre.period, post.period, model.args = list(nseasons = season))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment