This is the code for the Markov-Switching Cointegrating shiny app I used in my 2015 R/Finance presentation. The app is avilable online here: https://mattbrigida.shinyapps.io/MSCP/
Much of the code was also used in my 2014 Energy Economics publication:
Brigida, Matthew. "The switching relationship between natural gas and crude oil prices." Energy Economics 43 (2014): 48-55.