So the API of the sliderInput
widget allows you to set a min and a max and then it gives you a range between the min and max where the range is evenly divided. Is it possible to give sliderInput
a vector of all the values you want and have the slider only able to land in one of those values in the vector?
Asked
Active
Viewed 629 times
7

Bear Bile Farming is Torture
- 4,317
- 4
- 27
- 61
-
It's a good question. Maybe you can do it by having an integer range but changing the labels on the ticks marks. It might need to be done in javascirpt or css though. I don't think shiny includes that functionality. – Simon Woodward Nov 05 '20 at 05:47
-
Why not use dropdown with all possible values then? – Ronak Shah Nov 05 '20 at 06:00
-
@RonakShah The victor is numeric with natural order. And there could be hundreds of values. Thus a slider range is more appropriate than a dropdown – Bear Bile Farming is Torture Nov 05 '20 at 06:30
-
2[This post](https://stackoverflow.com/questions/49490395/creating-a-categorical-sliderinput-within-a-rendered-ui-in-r-shiny), though not addressing your exact question, may point you in a useful direction. – Limey Nov 05 '20 at 07:54
1 Answers
4
I think the sliderTextInput
from shinyWidgets
does what you want. Though on the slider, all values are equally separated and not proportionnally.
library(shiny)
library(shinyWidgets)
ui <- fluidPage(
sliderTextInput(
inputId = "myslider",
label = "Choose a value:",
choices = c(2,3,5,7,11,13,17,19,23,29,31),
grid = TRUE
)
)
server <- function(input, output, session) {
observe(print(input$myslider))
}
shinyApp(ui, server)

gdevaux
- 2,308
- 2
- 10
- 19