[R] How to avoid endless loop in shiny
Greg Snow
538280 at gmail.com
Wed Mar 9 00:00:07 CET 2016
You need to use `isolate` on one of the assignments so that it does
not register as an update. Here are a few lines of code from the
server.R file for an example that I use that has a slider for r
(correlation) and another slider for r^2 and whenever one is changed,
I want the other to update:
observe({
updateSliderInput(session, 'r',
value=isolate(ifelse(input$r<0,-1,1))*sqrt(input$r2))
})
observe({
updateSliderInput(session, 'r2', value=input$r^2)
})
I did end up in a loop once when I happened to choose just the wrong
value and the rounding caused a jumping back and forth, but all the
other times this has worked perfectly without the endless loop.
On Tue, Mar 8, 2016 at 12:35 PM, Michael Peng
<michael.gang.peng at gmail.com> wrote:
> Hi,
>
> I added two sliderInput into the app with package "shiny": sliderA and
> sliderB. The values in the two sliders are correlated. If I change sliderA,
> I used updateSliderInput to update the value in sliderB. And also If I
> change sliderB, I used updateSliderInput to update the value in slideA.
>
> The problem is it is an endless loop. How can I use updateSliderInput
> without sending message to update the other slider.
>
> Thank.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com
More information about the R-help
mailing list