rshinynouislidershinywidgets

How do the `range` and `pips` arguments work in shinyWidgets `noUiSliderInput()`?


The documentation for shinyWidgets::noUiSliderInput() arguments of range and pip` simply state that they are to be a list, but do not provide any examples of the structure or content of the list.

I have reviewed the refreshless.com documentation on noUiSlider for making a nonlinear slider using range (https://refreshless.com/nouislider/examples/#section-non-linear), however matching that structure produces a blank ui and does not cause any errors.

Here is what I am attempting in R Shiny. Note that if the range argument is commented out, it does produce a slider in the UI:

library(shiny)
library(shinyWidgets)

if(interactive()) {
    ui <- fluidPage(
    
    tags$br(),
    
    noUiSliderInput(
      inputId = "noui2", 
      label = "Slider vertical:",
      min = 20, 
      max = 400000,
      #step = 50,
      value = c(100),
      orientation = "vertical",
      range = list("min" = 0,
                   "x20" = c(20, 5),
                   "x100" = c(100, 20),
                   "x250" = c(250, 50),
                   "x500" = c(500, 100),
                   "x5000" = c(5000, 1000),
                   "x20000" = c(20000, 20000),
                   "max" = 400000),
      width = "100px", height = "300px"
    ),
    verbatimTextOutput(outputId = "res2")
    
  )
    
  server <- function(input, output, session) {
    
    output$res2 <- renderPrint(input$noui2)
    
  }
  
  shinyApp(ui, server)

}


Solution

  • The keys of the range option must be given as % e.g.

          range = list("min" = list(0),
                       "20%" = list(20, 5),
                       "80%" = list(100, 50),
                       "max" = list(400))
    

    What are x20, x100, etc? You want custom tick labels? You can do:

          pips = list(
            mode = "values",
            values = list(0, 200, 400),
            density = 4
          )