I am trying to get the app to display a number of slider/numeric input pairs equal to the initial numeric input. I want each slider and numeric input pair to be coordinated with each other such they always display the same value, like in the example I have below. Any help is appreciated. Thank you.
library(shiny)
ui <- fluidPage(
titlePanel("Test"),
sidebarLayout(
sidebarPanel(
numericInput(inputId = "times", label = "Number of sliders", value = 1, min = 1, max = 100),
sliderInput(inputId = "Slider1", "Slider1", min = 1, max = 100, value = 50),
textInput(inputId = "Text1", "Text1", value = 50)
),
mainPanel(uiOutput("plots"))
)
)
server <- shinyServer(function(input, output, session) {
list_num <- reactiveValues(value=NULL)
list_index <- reactiveValues(value=NULL)
observeEvent(list_num$value, { updateSliderInput(session, "Slider1", max=list_num$value)
})
observeEvent(input$Slider1, { print(paste0("Slider1 initial value ", input$Slider1))
list_index$value <- input$Slider1
})
observeEvent(input$Text1, { print(paste0("Text1 initial value ", input$Text1))
list_index$value <- max(1, as.numeric(input$Text1))
})
observeEvent (list_index$value, {
if (is.na(input$Slider1) | is.na(list_index$value) | list_index$value != input$Slider1) { updateSliderInput(session, "Slider1", value=list_index$value) }
else {updateTextInput(session, "Text1", value=list_index$value)}
})
})
shinyApp(ui, server)