1

I want to plot a graph within a shiny app. Then I want to add multiple shades on the same graph. Before i show you my code let me define my sampe data.

dg= reactive ({dygraph(X1(), main ="interactive graph",
              xlab = "time frame",
              ylab = "records" ) %>% dyRangeSelector()  }) 

# I have a table for the shades to be added, it's defined with reactive

shade_tab=reactive({ Panne[Panne$Equipement==input$machine,] })  

# add shades

for( i in 1:nrow(shade_tab())) 
       { dg()= reactive({
               dyShading(dg(), from= shade_tab()$Date[i],
                               to  = shade_tab()$Date[i] + 24*60*60 , 
                             color = 'black'                                
                       })
       } 

  output$dygraph <- renderDygraph({ dg()() })

This is the code I tried to run, but it does not work. Any help will be greatly appreciated.

smerllo
  • 3,117
  • 1
  • 22
  • 37
  • Please try to make a proper [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) that we can copy/paste into R and run. You should not be trying to assign to a reactive() object. I'm not sure when you expect that `for` loop to run, bit it seems like it should probably be inside the `dg` reactive expression. – MrFlick Apr 05 '17 at 16:07

1 Answers1

1

Reactive expressions must be called inside reactive environments. So shade_tab() will not work in that for since is outside a reactive environment. You could fix that, wrapping the forinside an observe.

The basics section at https://shiny.rstudio.com/articles/ explains this really well :)

user5029763
  • 1,903
  • 1
  • 15
  • 23