rstudio / shiny

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

slider with limited number of allowed values #707

Open slowkow opened 9 years ago

slowkow commented 9 years ago

I'd like to request a slider with a limited number of allowed values instead of a continuous scale of values.

In other words, it could be a radio button that is displayed as a slider.

Perhaps something like this:

sliderInput("window.size", "Window size (days)",
            allowed.values = c(7, 31, 91, 183, 365),
            value = 7)

One possible use-case for this feature is to restrict the user to select reasonable windows:

This prevents the user from selecting other window sizes that are difficult to interpret because they do not correspond to some regular time interval.

jcheng5 commented 9 years ago

It might make sense to represent that as a selectInput instead. But if you do want to go this route, while we're missing this feature in the client side where it would be best, you could probably simulate it with something like this in server.R (in this example, the name of the slider is "slider1":

observe({ snapTo <- c(0,7,31,91,183,365) value <- snapTo[match(1, order(abs(input$slider1 - snapTo)))] updateSliderInput(session, "slider1", value = value) })

On Tue, Jan 27, 2015 at 8:38 AM, Kamil Slowikowski <notifications@github.com

wrote:

I'd like to request a slider with a limited number of allowed values instead of a continuous scale of values.

In other words, it could be a radio button that is displayed as a slider.

Perhaps something like this:

sliderInput("window.size", "Window size (days)", allowed.values = c(7, 31, 91, 183, 365), value = 7)

One possible use-case for this feature is to restrict the user to select reasonable windows:

  • 7 days (1 week)
  • 31 days (1 month)
  • 91 days (1 season)
  • 183 days (half year)
  • 365 days (1 year)

This prevents the user from selecting other window sizes that are difficult to interpret because they do not correspond to some regular time interval.

— Reply to this email directly or view it on GitHub https://github.com/rstudio/shiny/issues/707.

wch commented 9 years ago

It does appear that the underlying ion.rangeSlider allows custom labels -- the visual step size must be equal, but the label can be customized.

That said, this functionality isn't currently exposed with sliderInput. It might in the future, possibly along with date support (#689).