R shiny bi-directional reactive widgets

前端 未结 2 480
一向
一向 2020-12-29 15:17

I am struggling to figure out how to get 2 R Shiny widgets to update each other. For example, a slider widget that can update a text box widget, and visa versa, where the en

2条回答
  •  天涯浪人
    2020-12-29 15:35

    If you enclose each input slider under a reactive observe, you can achieve your goal. This not only works for two inputs, but for several inputs as well. Let me explain by an example:

    observe({
    # Create a reactive relationship with slider1
    input$slider1
    # Update the second slider - slider2
    updateTextInput(session, "slider2", NULL, input$slider1)
    )}
    

    Similarly for second input, you'd have to repeat the code, by:

    observe({
    # Create a reactive relationship with slider2
    input$slider2
    # Update the second slider - slider1
    updateTextInput(session, "slider1", NULL, input$slider2)
    )}
    

提交回复
热议问题