Hi,
Here is an example of your request
library(shiny)
library(dplyr)
data_13_Sam <- data.frame(
Ratings = c(1,2,3,4,5,1,2,3,4,5),
flag = c("Yes","No","Yes","No","Yes","No","Yes","No","Yes","Yes")
)
ui <- fluidPage(
selectInput("rat",label = tags$h4("Ratings"),choices = 1),
selectInput("flag",label = tags$h4("Flag"),choices = "Yes")
)
server <- function(input, output, session) {
observeEvent(input$rat, {
updateSelectInput(session, "flag",
choices = data_13_Sam %>% filter(Ratings == input$rat) %>%
pull(flag) %>% sort())
})
observeEvent(input$flag, {
updateSelectInput(session, "rat",
choices = data_13_Sam %>% filter(flag == input$flag) %>%
pull(Ratings) %>% sort())
})
}
shinyApp(ui, server)
Instead of rendering the input boxes, I created them with default values being the first combination, then used the updateSelectInput to change the values based-off the selections made. They will trigger eachother if the other one changes.
That said, the logic is a bit weird since you want it to go in both directions. For example, in the default scenario: Ratings = 1 and Flag = No (option Yes also available, but sorted alphabetically here). This means option 5 is not visible in the Ratings dropdown, so if a user wants to see this, they need to know to set flag first to Yes before they can select 5from Ratings. This is very confusing and complicated. I don't really see why you would like to do that.
PJ