Even thought there are many topics dealing with the properties of the sliderInput in Shiny, I couldn't find a solution to what I'm trying to do.
My problem is simple: I would like to adapt my code (see below) in order to create a slider with an interval of "10" (from 0 to 10, 10 to 20, 3 to 13 etc...)
###running example:
ui <-basicPage(
sliderInput("id", "Ranking",
min = 2, max = 60, value = c(2,15)))
server <- server <- function(input, output) {}
shinyApp(ui, server)
Any ideas please ?
You can call updateSliderInput every time the slider is changed, to enforce the interval.
The trick here is to remember previous value to update the right handler (the one that that didn't change)
INTERVAL = 13
value = c(2, 2 + INTERVAL)
ui <-basicPage(
sliderInput("id", "Ranking",
min = 2, max = 60, value = value))
server <- server <- function(input, output, session) {
observeEvent(input$id,{
newvalue = input$id
if(value[1] != newvalue[1] && newvalue[2] - newvalue[1] != INTERVAL)
updateSliderInput(session, "id", value = c(newvalue[1], newvalue[1] + INTERVAL))
if(value[2] != newvalue[2] && newvalue[2] - newvalue[1] != INTERVAL)
updateSliderInput(session, "id", value = c(newvalue[2] - INTERVAL, newvalue[2]))
value <<- newvalue
})
}
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With