Home > Software design >  Shiny sliderInput keeps displaying decimals
Shiny sliderInput keeps displaying decimals

Time:11-19

I'm trying to create a slider. None of the base values I'm working with have decimals in them, so I have no idea why this continues to happen. I also have set the round parameter within the function as round = TRUE.

library(shiny)

test_df <- 19:45

ui <- fluidPage(

sliderInput("range1", label = h3("Select Range"), min(test_df), 
            max(test_df), value = c(min(test_df), max(test_df)), round = TRUE)
)

server <- function(input, output, session){
    
}

shinyApp(ui, server)

But as you can see, when you run it, it keeps showing numbers with decimals in the slider range.

I'm clearly missing something but have no idea as to what it is.

enter image description here

CodePudding user response:

It looks like inputSlider made 10 ticks on your slider, regardless of whether or not that makes sense. 45-19=26, 26/10=2.6, and we are seeing steps of 2.6 on the slider. We can add a step argument to fix the slider so it moves in increments of 1 or whatever you choose.

library(shiny)

test_df <- 19:45

ui <- fluidPage(
  
  sliderInput("range1", label = h3("Select Range"), min(test_df), 
              max(test_df), value = c(min(test_df), max(test_df)), round = TRUE,
              step = 1)
)

server <- function(input, output, session){
  
}

shinyApp(ui, server)
  • Related