1

I'm writing a shiny app on rmarkdown. The app supposes to plot two time series on the same chart, but the second plot is conditional on a checkbox.

The problem is that when the checkbox is left unchecked, the whole chart disappears, instead of only the series related to the checkbox.

I'm currently using the plot.xts from xtsExtra pkg, but I'm willing to try other pkgs. The only restriction is that color (col) and line weight (lwd) must be customized.

---
title: "Untitled"
author: "gustavo"
date: "Saturday, November 29, 2014"
output: html_document
runtime: shiny
---


```{r, echo = FALSE}
require(xts)
require(xtsExtra)

x = rnorm(100)
y = rnorm(100)
idx = seq(as.Date("2000-01-01"), length = 100, by = "months")

Xxts = xts(cbind(x,y), order.by = idx)

checkboxInput("teste", "Teste", value = FALSE)

renderPlot({
  plot.xts(Xxts[,1],panel = 1)
  
  if(input$teste == TRUE){
  addSeries(Xxts[,2], on = 1, type="l")
  }
})

```
Gustavo
  • 65
  • 1
  • 6

1 Answers1

1

Change your renderPlot to

renderPlot({ 
  if(input$teste == TRUE){
    plot.xts(Xxts[,1],panel = 1)
    addSeries(Xxts[,2], on = 1, type="l")
  }else{
    plot.xts(Xxts[,1],panel = 1)
  }
})

enter image description here

jdharrison
  • 30,085
  • 4
  • 77
  • 89