I try to make two mutually dependent input sliders in a shiny app but don't seem to get it to work. I plan to use this kind of situation in a shiny app and for ease illustrate it here with a simplified 'glass half empty / full' example in which one slider should show glass fullness and one emptyness:
library(shiny)
ui =(pageWithSidebar(
headerPanel("Glass fullness"),
sidebarPanel(
sliderInput("Full", "% water", min = 0, max = 1, value = 0.2),
#display dynamic UI
uiOutput("Empty")),
mainPanel()
))
server = function(input, output, session){
# make dynamic slider
output$Empty <- renderUI({
sliderInput("Empty", "% air", min=0, max=1, value=1-input$Full)
})
}
runApp(list(ui = ui, server = server))
I understand the value = 0.2
and value=1-input$Full
cause above code only to make the second slider dependent on the first but not the other way around. My problem is that I want to make both dependent on each other. I tried adding an uiOutput("Full") & dynamic slider for Full but did not manage to work around circular coding.
The result of above code looks as follows:
Glass half empty/full screenshot
Any help greatly appreciated!