Search code examples
rggplot2shinyggplotly

shiny slider with button for increment and decrement


Is there a possibility for sliders in shiny to have buttons for increment and decrement, instead of dragging the slider?


Solution

  • Maybe my package shinyChakraSlider is suitable. The chakraSliderInput combines a slider and a number input:

    enter image description here

    Here is the code generating the app you see on this GIF:

    library(shiny)
    library(shinyChakraSlider)
    
    ui <- fluidPage(
      br(),
      chakraSliderInput("slider", value = 5, min = 0, max = 10, step = 0.5,
                        width = "50%", size = "lg",
                        numberInputOptions = numberInputOptions(
                          width = "25%",
                          fontSize = "15px", 
                          fontColor = "navyblue",
                          borderColor = "yellow",
                          borderWidth = "medium",
                          focusBorderColor = "navyblue",
                          stepperColor = c("palegreen", "palevioletred")
                        ),
                        trackColor = c("red", "blue"),
                        thumbOptions = thumbOptions(
                          width = "40px",
                          height = "30px",
                          color = "pink",
                          borderColor = "magenta",
                          borderWidth = "2px",
                          icon = "arrows",
                          iconSize = "2em"
                        )
      ),
      br(),
      verbatimTextOutput("value")
    )
    
    server <- function(input, output){
      output[["value"]] <- renderPrint({
        input[["slider"]]
      })
    }
    
    shinyApp(ui, server)
    

    To install this package:

    devtools::install_github("stla/shinyChakraInput")