Trigger ObserveEvent for dynamic SelectInput in R Shiny

I am generating dynamic selectinput in below code, creating separate UI for each row. I want to show or hide other selectinput based on selection of choices. I have been trying to bind ObserveEvent for selectinput and for that I have googled so many but failed to find out.

    library(shiny)   
    library(shinyWidgets)

    ui = fluidPage(  
         absolutePanel(
          left="20px",
          top="250px",
          width="auto",
          id="listPanel",
          
          column(
            width=6,
            
            uiOutput("redeploymentViewUI")
            
            )
          ) 
    )
    server = function(input,output,session){
         output$filtersUI=renderUI({
            div(
              div(
                
              
              ID="firstRow",
              div(
                style="display: inline-block;vertical-align:top;width: 35px;padding-top:5%;cursor:pointer;",
                actionButton(
                  "AddButton_1",
                  HTML("<i class='fas fa-plus' style='color:black;' title='Add more filter'></i>"),
                  class="filterbuttons",
                  onclick="Shiny.onInputChange('Add_Row_button','1')"
                )
               
              ),
              div(
                style="display: inline-block;vertical-align:top;width: 150px;",
                # Filter by Segment - I want to trigger here ObserverEvent
                selectInput(
                  inputId="FilterField_1",
                  label="Field",
                  choices=c("Employee","State","Status","Supervisor"),
                  multiple=F,
                  selectize = F
                )
              ),
              div(
                style="display: inline-block;vertical-align:top;width: 150px;",
                selectInput(
                  inputId="FilterOperator_1",
                  label="Operator",
                  choices=c("Begins with","Equals to","Not Equals to","Contains","Not Contains"),
                  multiple=F,
                  selectize = F
                  
                )
              ),
              div(
                style="display: inline-block;vertical-align:top;width: 150px;display:none",
                selectInput(
                  inputId="FilterState_1",
                  label="State",
                  choices=sort(unique(c("",df$db$WORK_STATE))),
                  multiple=F,
                  selectize = F
                )
              ),
              div(
                style="display: inline-block;vertical-align:top;width: 200px;",
                textInput("FilterValue_1", "Value")
              )
              ),
              br(),
              br(),
              div(
                style="display: inline-block;vertical-align:top;width: 150px;",
                actionButton("applyFilter", "Apply Filter"),
                actionButton("reset", "Clear")
              )
              
            )
           
          })
          
          # Redeployment View UI -----------------------------
          output$redeploymentViewUI = renderUI({
            
            box(
              width=NULL,
              solidHeader=TRUE,
              title="Redeployment View",
              
              uiOutput("buttonsUI"),
              br(),
              uiOutput("filtersUI"),
              br(),
              dataTableOutput("redeployView")
              
            )
            
          })
observeEvent(input$Add_Row_button,{
    if(input$Add_Row_button!=""){
      
    filterRow$CurrentRow= filterRow$CurrentRow +1
    
    
    insertUI(
      selector = "#firstRow",
      where = "beforeEnd",
      ui=({
        div(
          id=paste("div",filterRow$CurrentRow,sep = ""),
          div(
            style="display: inline-block;vertical-align:top;width: 35px;padding-top:4%;cursor:pointer;",
            actionButton(
              inputId=paste("DeleteButton",filterRow$CurrentRow,sep = "_"),
              class="filterbuttons",
              label = HTML("<i class='fas fa-minus' style='color:black;' title='Remove this'></i>"),
              onclick=paste0("Shiny.onInputChange('Delete_Row_button',",filterRow$CurrentRow,")")
              
            )
            
          ),
          div(
            style="display: inline-block;vertical-align:top;width: 150px;",
           # Filter by Segment - I want to trigger here ObserverEvent same event of above code. 
            selectInput(
              inputId=paste("FilterField",filterRow$CurrentRow,sep = "_"),
              label="",
              choices=c("Employee","State","Status","Supervisor"),
              multiple=F,
              selectize = F
            )
          ),
       
         div(
          style="display: inline-block;vertical-align:top;width: 150px;",
          selectInput(
            inputId=paste("FilterOperator",filterRow$CurrentRow,sep = "_"),
            label = "",
            choices=sort(unique(c("Begins with","Equals to","Not Equals to","Contains","Not Contains"))),
            multiple=F,
            selectize = F
            
          )
        ),
        div(
          style="display: inline-block;vertical-align:top;width: 150px;display:none",
          selectInput(
            inputId=paste("FilterState",filterRow$CurrentRow,sep = "_"),
            label="",
            choices=sort(unique(c("",df$db$WORK_STATE))),
            multiple=F,
            selectize = F
            
          )
        ),
        div(
          style="display: inline-block;vertical-align:top;width: 200px;",
          textInput(paste("FilterValue",filterRow$CurrentRow,sep = "_"),label =" ")
        ),
        br()
       
        )
      })
    )
    }
    runjs("Shiny.onInputChange('Add_Row_button','');")
  })
  
  observeEvent(input$Delete_Row_button,{
    if(input$Delete_Row_button!=""){
      filterCRow<- as.numeric(input$Delete_Row_button)
      removeUI(selector = paste("div#div",filterCRow,sep=""))
      filterRow$CurrentRow= filterRow$CurrentRow-1
    }
    
    runjs("Shiny.onInputChange('Delete_Row_button','');")
  })
    }

can we bind same ObserveEvent for all generated SelectInput like Shiny.OnInputChange for actionbutton

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.