Skipping a value between min and max values when using selectInput function in Shiny

207 views Asked by At

I am working on a Shiny application and I was wondering if it was possible to skip one value between the min and max values passed in the selectInput function. I have this:

sliderInput(inputId="timeseries.year", label="Select Year or press play:",  min=1970, max=2011, value=1994, step = 1,sep="",                 animate=animationOptions(interval=700,loop=F)

So the min is 1970 and the max is 2011 and I want to exclude the value 1993 (because it is missing). Please let me know if there is a way to do this!

1

There are 1 answers

0
DeanAttali On

It looks like shiny uses ion rangeslider for its inputSlider. Looking at the docs, it does look like it's possible to have custom values, either by adding a data-values attribute before initialization, or you can update the slider after it's been initialized. Here is a very hacky way to achieve the second approach. It can probably be a lot cleaner, but basically what I'm doing is adding JavaScript that updates the values parameter of the slider 5 milliseconds after the app initializes. I'm doing this hacky 5 millisecond thing simply because I don't know what's the right way to know when shiny is ready. There must be a cleaner way of determining when to make that call, but the idea of updating the slider still holds. Hope this helps

library(shiny)
JScode <-
  "$(function() {
    setTimeout(function(){
      $('#myslider').data('ionRangeSlider').update({'values':[1,2,3,5]})
    }, 5)})"

runApp(shinyApp(
  shinyUI(fluidPage(
    tags$head(tags$script(JScode)),
    sliderInput("myslider", "Slider", 1, 5, 3)
  )),
  server = function(input,output,session) {

  }
))