Please find the working code below.
Basically, there are 3 numericInputs which allows the user to change anyone at a time and the other 2 should adapt themselves resulting in 1
A + B + C = 1
However, since they are interlinked, they seems to be unstable.
How can we make it stable and allow the user to change any 1 variable: A and other 2 change themselves summing to 1. similar question similar1
I've handled this situation with sliders where the 2nd slider depends on the first and the 3rd slider depends on the first 2. The third slider is disabled (using shinyjs package) so that the value is shown but can't be changed. Here is your example modified to show that approach:
library(shiny)
library(shinyjs)
u <- shinyUI(fluidPage(
useShinyjs(),
titlePanel("Mutually Dependent Input Values"),
sidebarLayout(
sidebarPanel(
sliderInput("A", "A", min = 0, max = 1, value = 0.33, step = 0.01),
sliderInput("B", "B", min = 0, max = 0.67, value = 0.33, step = 0.01),
sliderInput("C", "C", min = 0, max = 1, value = 0.34, step = 0.01)
),
mainPanel(
verbatimTextOutput("result")
)
)
))
s <- shinyServer(function(input, output,session) {
observeEvent(input$A,{
updateSliderInput(session, "B", max = 1 - input$A)
disable("C") # putting this here keeps the slider disabled all the time (but still shows updating)
})
observe({
updateSliderInput(session, "C", value = 1 - input$A - input$B)
})
})
shinyApp(u,s)
@hinkelman, Can you please help to ensure numericInput rendered using renderUI doesnt allow user to update the value i.e Although Label1,2 and 3 are calculated based on Value1,2 and 3, User can still increase or decrease the Label values. Can we somehow disable this. So that user cannot vary the Labels ?