jeudi 20 août 2020

R Shiny: How to disable/enable slider via checkbox?

The following code produces an example with three sliders and three checkboxes.

If one checkbox is ticked the slider below should be disbaled. That means the selected value should not be modifiable by the slider anymore.

Furthermore the sum of all slider values should not extend the maximum value, in this case 10.

library(shiny)

u <- shinyUI(fluidPage(
    titlePanel("title panel"),
    sidebarLayout(position = "left",
                  sidebarPanel("sidebar panel",
                               checkboxInput("check1", "disable/enable", value = T),
                               sliderInput("slider1","value 1",min=1,max=10,value=3),
                               checkboxInput("check2", "disable/enable", value = F),
                               sliderInput("slider2","Value 2",min=1,max=10,value=3),
                               checkboxInput("check3", "disable/enable", value = F),
                               sliderInput("slider3","Value 3",min=1,max=10,value=3)
                  ),
                  mainPanel("main panel")
                  )))

s <- shinyServer(function(input, output){})
shinyApp(u,s)



Aucun commentaire:

Enregistrer un commentaire