I want to create a brilliant application with two slides that add up to 100. This means that if the user changes the value of one slider, the other slider automatically changes to fulfill the constraint (100-input $ slider1).
I found a similar question here:
Code example
with the following code:
Server:
library(shiny)
shinyServer(function(input, output) {
output$slider2 <- reactiveUI(function() {
sliderInput("slider2", "Slider 2", min = 0, max = 100 - input$slider1, value = 0)
})
output$restable <- renderTable({
myvals<- c(input$slider1, input$slider2, 100-input$slider1-input$slider2)
data.frame(Names=c("Slider 1", "Slider 2", "Slider 3"),
Values=myvals)
})
})
interface:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Sliders should sum to 100!"),
sidebarPanel(
sliderInput("slider1", "Slider 1: ", min = 0, max = 100, value = 0, step=1),
uiOutput("slider2")
),
mainPanel(
tableOutput("restable")
)
))
This is already a solution, which is in order. But here you can only change the slider 1 to automatically change the slider 2. On the other hand, if the user changes the slider 2, then slider 1 does not fit the limit. How can I make this possible so that both sliders can be changed so that the other meets the constraints?