Shiny Slider Customized Values

前端 未结 4 1684
一向
一向 2020-12-19 12:53

I am trying to set custom values for shiny slider (1,5,10,15,20,25 and 30). I tried step but then the results either (0,5,10,15,20,25,30) or (1,6,11,16,21,26,31

相关标签:
4条回答
  • 2020-12-19 13:32

    This can be easily done using sliderTextInput function in shiny. No need to add all this complex js function. Just a few lines of code will do the trick.Install the shinywidgets package which contains the sliderTextInput function. Do the following :

      sliderTextInput("decade","Time (decade):, 
                      choices = c(1,5,10,15,20,25,30), 
                      selected = c(1,5,10,15,20,25,30), 
                      animate = FALSE, grid = FALSE, 
                      hide_min_max = FALSE, from_fixed = FALSE,
                      to_fixed = FALSE, from_min = NULL, from_max = NULL, to_min = NULL,
                      to_max = NULL, force_edges = FALSE, width = NULL, pre = NULL,
                      post = NULL, dragRange = TRUE)
    
    0 讨论(0)
  • 2020-12-19 13:41

    Depending on the need to have a slider, to have inputs with variable breaks you could use one of the other options, like

    selectInput

    https://shiny.rstudio.com/reference/shiny/latest/selectInput.html

    or even checkboxInput

    https://shiny.rstudio.com/reference/shiny/latest/checkboxInput.html

    0 讨论(0)
  • 2020-12-19 13:43

    The shinyWidgets package now solves this for you with a slider that allows custom values. Updated code for your third slider would look like this:

    shinyWidgets::sliderTextInput(inputId = "decade", 
      label = "Time (decade):", 
      choices = c(1,5,10,15,20,25,30))
    
    0 讨论(0)
  • 2020-12-19 13:46

    Although Shiny gives options to customize the slider Input,I do not think there is a way to to get output in the form (1,5,10...).This is because the difference between your 1st and 2nd point is 4 and thereafter it is 5 which will be inconsistent with the way step parameter works.Step can only generate numbers based on constant differences between slider inputs.

    0 讨论(0)
提交回复
热议问题