rstudio / shiny

Easy interactive web applications with R
https://shiny.posit.co/
Other
5.35k stars 1.87k forks source link

Rate policies for inputs should be customizable #1087

Open wch opened 8 years ago

wch commented 8 years ago

For example, a sliderInput currently is debounced with a 250ms delay, but that can't be changed: https://github.com/rstudio/shiny/blob/b658983/srcjs/input_binding_slider.js#L101-L106

It would be useful to be able to pass an option to change that.

Also, for sliders in particular, it would be useful to have an option that only updates the input when the slider is released.

daattali commented 8 years ago

@homerhanumat I think you were talking about trying to implement this yourself? Tagging you so you can follow any developments on this feature

homerhanumat commented 8 years ago

Yes, @wch, an option within shiny for customization would be convenient. in the meantime you could try my package shinyCustom. It borrows some ideas from @daattali to permit the user to accomplish the customization directly within R.

homerhanumat commented 8 years ago

Hold on, I just noticed that @wch is Winston Chang. So you would know how to do this already!

On Wed, Jan 20, 2016 at 10:52 PM, Dean Attali notifications@github.com wrote:

@homerhanumat https://github.com/homerhanumat I think you were talking about trying to implement this yourself? Tagging you so you can follow any developments on this feature

— Reply to this email directly or view it on GitHub https://github.com/rstudio/shiny/issues/1087#issuecomment-173443606.

daattali commented 8 years ago

Yes, I think this issue was more of a "note to self and to my fellow developers: this is something we should do soon" :+1:

homerhanumat commented 8 years ago

OK, so while we are at it: I have also heard seen requests that text inputs have the option to update under more restrictive conditions, i.e., if and only if the user presses Enter or shifts focus outside of the input area.

wch commented 8 years ago

:) Thanks, those are useful ideas. Ideally we'll have a nice, consistent way for users to configure inputs to send values at different times.

nuno-agostinho commented 7 years ago

Hey, everyone! As @wch mentioned:

Also, for sliders in particular, it would be useful to have an option that only updates the input when the slider is released.

This has not yet been developed. The slider input makes use of the ion.rangeSlider.js library, which allows to only capture the value when the user finishes the selection through a JavaScript callback to onFinish, as demonstrated in here. Aren't we able to simply use that function to only retrieve values when the user stops changing the slider?

LaFeh commented 2 years ago

are there any news on this issue? Is it already impelemented?

cpsievert commented 2 years ago

Yes, it's implemented now as getRatePolicy https://shiny.rstudio.com/articles/js-custom-input.html#additional-methods

wch commented 2 years ago

I don't think there's a way to actually set the rate policy though; the return value of getRatePolicy is hard-coded. https://github.com/rstudio/shiny/blob/40ae9a903e6c8e20acbf0e6691f75b6b45bb7f99/srcts/src/bindings/input/slider.ts#L232-L236

rwb27 commented 1 year ago

I've just taken a look at this, as we wanted to make slider controls more responsive for some demos. I put together a very simple solution that modifies the hard-coded responses above:

getRatePolicy(i){
  policy = i.attributes["data-rate-policy"] || "debounce";
  delay = i.attributes["data-rate-policy-delay"] || 250;
  return ({policy:policy,delay:delay});
}

I've also put together a little R wrapper function that adds the relevant attributes to the code produced by shiny::sliderInput and injects the JavaScript. I suspect you neither need nor want to see how I monkey-patched the code into the input binding, but if there's a neat way to extend an existing input binding rather than writing a whole new one, I'd be curious.

If a pull request would be helpful, I'll happily try to put one together (with the caveat that I'm extremely rusty on R, a bit unsure of javascript, and haven't contributed to R Shiny before).