2

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)

}

jzadra
  • 4,012
  • 2
  • 26
  • 46

1 Answers1

3

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
      )
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • Thank you. Is there a way to format the labels for the values of the pips? For instance if I want to show "400k" instead of "400000"? – jzadra Apr 17 '23 at 20:51
  • 1
    @jzadra No and yes. You have to set the value to 400 and you can add the suffix `k`, by including `format = wNumbFormat(suffix = "k", decimals = 0)` in the `pips` list. – Stéphane Laurent Apr 17 '23 at 21:14
  • THanks. I'm looking more to pass it a function that adds the SI units as appropriate (400,000 = 4k, 4,000,000 = 4M, etc) – jzadra Apr 17 '23 at 21:42
  • 1
    @jzadra this is possible with the JavaScript library by passing some functions to the `format` option but I don't think **shinyWidgets** allows to pass some JavaScript functions. – Stéphane Laurent Apr 17 '23 at 21:48
  • 1
    @jzadra Ah no it is possible ! I did it in the past: https://stackoverflow.com/a/54605592/1100107 Maybe open a new question and I'll try. – Stéphane Laurent Apr 17 '23 at 21:51
  • @jzadra I opened and answered the question: https://stackoverflow.com/q/76039917/1100107 – Stéphane Laurent Apr 17 '23 at 23:11