shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Rate policies for inputs should be customizable

Open wch opened this issue 9 years ago • 10 comments

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.

wch avatar Jan 20 '16 15:01 wch

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

daattali avatar Jan 21 '16 03:01 daattali

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 avatar Jan 21 '16 10:01 homerhanumat

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 [email protected] 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.

homerhanumat avatar Jan 21 '16 10:01 homerhanumat

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:

daattali avatar Jan 21 '16 11:01 daattali

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.

homerhanumat avatar Jan 21 '16 11:01 homerhanumat

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

wch avatar Jan 21 '16 14:01 wch

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?

nuno-agostinho avatar Jun 02 '17 10:06 nuno-agostinho

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

LaFeh avatar Mar 15 '22 07:03 LaFeh

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

cpsievert avatar Apr 26 '22 21:04 cpsievert

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

wch avatar Apr 27 '22 00:04 wch

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

rwb27 avatar Dec 30 '22 23:12 rwb27