I have slider inputs on multiple panels which I want to mirror each other. If you change one, then all the others get changed ... as do the things which depend on them. I can do this without a problem, by using a reactiveValues variable, but I'm trying to generalise it.
The following method catches SL2 and adjusts SL1 to match, but doesn't catch SL1.
library(shiny)
ui <- function(request) {
fluidPage(
sliderInput("sl1","SL1",0,100,20),
sliderInput("sl2","SL2",0,100,20),
)
}
tieSliders<-function(v,s,tag,input,session) {
for(i in s) {
print(paste0("set v: ",i))
observeEvent(input[[i]],{
v[[tag]]<-input[[i]]
})
}
observeEvent(v[[tag]], {
for(i in s) {
print(paste0("setting: ",i))
if (input[[i]]!=v[[tag]]) { updateSliderInput(session,i,value=v[[tag]]) }
}
})
}
server<-function(ui,input,output,session) {
v<-reactiveValues(u=NULL)
tieSliders(v,c("sl1","sl2"),"sl",input,session)
}
shinyApp(ui=ui, server=server )
Perhaps I'm making wrong assumptions about arguments ?? Not sure.
Many thanks to anybody who can solve this.
Cheers,
Geoff