I have a small R Shiny app that has two options for setting 4 selectInput
fields. They can be selected manually, or through an action button that selects random values taken as a sample of 1 from the available choices in the 4 selectInput
fields.
When I run my button with the code below, it works well, but then the choice is overwritten by a different value:
observeEvent(input$button1, {
x = sample(Fifa23$Full.Name,1)
updateSelectInput(session, "Nationality",
choices = unique(Fifa23$Nationality),
selected = Fifa23$Nationality[Fifa23$Full.Name == x])
updateSelectInput(session, "Club",
choices = unique(Fifa23$Club[Fifa23$Nationality==input$Nationality]),
selected = Fifa23$Club[Fifa23$Full.Name == x])
updateSelectInput(session, "Position",
choices = unique(Fifa23$Position[Fifa23$Nationality==input$Nationality & Fifa23$Club==input$Club ]),
selected = Fifa23$Positions[Fifa23$Full.Name == x])
updateSelectInput(session, "Name",
choices = unique(Fifa23$Full.Name[Fifa23$Nationality==input$Nationality & Fifa23$Club == input$Club & Fifa23$Position == input$Position]),
selected = Fifa23$Full.Name[Fifa23$Full.Name==x])
})
where my observe, for manual selection of selectInput() values as is follows:
observe({
# Can also set the label and select items
updateSelectInput(session, "Club",
choices = unique(Fifa23$Club[Fifa23$Nationality==input$Nationality])
)
})
observe({
updateSelectInput(session, "Position",
choices = unique(Fifa23$Position[Fifa23$Nationality==input$Nationality & Fifa23$Club==input$Club ])
)
})
observe({
updateSelectInput(session, "Name",
choices = unique(Fifa23$Full.Name[Fifa23$Nationality==input$Nationality & Fifa23$Club == input$Club & Fifa23$Position == input$Position])
)
})
thank you for your help in advance.
I tried changing the arguments for Observe() like setting the suspend to TRUE, and the autoDestroy to TRUE, but I'm facing the same issue.