Slider

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

library(shiny)
library(bslib)

ui <- page_fluid(
  sliderInput("slider", "Slider", 
              min = 0, max = 100, value = 50), 
  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 = 50), 
  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.

To add a slider to your app:

  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. Set the value parameter to define the starting slider value. min, max, and value can be numbers, dates, or date-times (POSIXct).

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 is a number, date, or date-time (depending on the class of value).

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 = 50,
    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