Slider Range

#| standalone: true
#| components: [viewer]
#| viewerHeight: 200

library(shiny)
library(bslib)

ui <- page_fluid(
  sliderInput( 
    "slider", "Slider", 
    min = 0, max = 100, 
    value = c(35, 65) 
  ), 
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderPrint({input$slider})
}

shinyApp(ui = ui, server = server)
library(shiny)
library(bslib)

ui <- page_fluid(
  sliderInput( 
    "slider", "Slider", 
    min = 0, max = 100, 
    value = c(35, 65) 
  ), 
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderPrint({input$slider})
}

shinyApp(ui = ui, server = server)
No matching items

Relevant Functions

  • sliderInput
    sliderInput(inputId, label, min, max, value, step = NULL, round = FALSE, ticks = TRUE, animate = FALSE, width = NULL, sep = ",", pre = NULL, post = NULL, timeFormat = NULL, timezone = NULL, dragRange = TRUE)

  • animationOptions
    animationOptions(interval = 1000, loop = FALSE, playButton = NULL, pauseButton = NULL)

No matching items

Details

A slider is a widget that lets you drag to select a number, date, or date-time from a specified range. You can use a slider to select either a single value or a range of values.

To add a slider that lets the user select a range of values:

  1. Add sliderInput() to the UI of your app to create a slider. Where you call this function will determine where the slider will appear within the app’s layout.

  2. Specify the inputId and label parameters of sliderInput() to define the identifier and label of the slider.

  3. Use the min and max parameters to define the minimum and maximum values of the slider.

  4. Pass a vector with two elements to the value parameter. These elements define the initial range. value can be a list of numbers, dates, or date-times.

The value of an input component is accessible as a reactive value within the server() function. To access the value of a slider:

  1. Use input$<slider_id> (e.g., input$slider) to access the value of the slider. The server value of a slider with two input values will be a vector of length 2.

See also

Variations

Animated Slider

To provide a play button alongside the slider, set the animate parameter to TRUE. When a user presses the play button, the slider will iterate over its range of values. Set animate to the animationOptions() helper to customize the animation behavior.

library(shiny)
library(bslib)

ui <- page_fluid(
  sliderInput(
    "slider", "Slider", min = 0, max = 100, value = c(40, 60),
    animate = animationOptions(interval = 100, loop = TRUE)), 
  verbatimTextOutput("value")
)

server <- function(input, output) {
  output$value <- renderPrint({input$slider})
}

shinyApp(ui = ui, server = server)
No matching items