shiny
shiny copied to clipboard
Rate policies for inputs should be customizable
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.
@homerhanumat I think you were talking about trying to implement this yourself? Tagging you so you can follow any developments on this feature
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.
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.
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:
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.
:) Thanks, those are useful ideas. Ideally we'll have a nice, consistent way for users to configure inputs to send values at different times.
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?
are there any news on this issue? Is it already impelemented?
Yes, it's implemented now as getRatePolicy
https://shiny.rstudio.com/articles/js-custom-input.html#additional-methods
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
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).