smerllo
smerllo

Reputation: 3375

How can I apply reactive() on reactive object?

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.

Upvotes: 1

Views: 51

Answers (1)

user5029763
user5029763

Reputation: 1933

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 :)

Upvotes: 1

Related Questions