Persistent selected values using modal selectInput


I would like to create use a select input inside a modal dialog box. The problem I encountered is that the selected values are cleared each time the modal dialog opened. In other words the selected values do not persist when using selectInput inside a modal dialog box. To solve this problem I made the select input a reactive expression that depends on it's own reactive value. This works but I'm worried about creating a loop in the graph of dependencies. I'm just looking for some feedback from a more experienced Shiny programmer. Is this OK? Is there a better approach?



ui <- fluidPage(
     actionButton("button", "Button"),

server <- function(input, output) {
     my_input <- reactive(selectInput("letters", "letters", selected = input$letters, choices = letters, multiple = T))
     observeEvent(input$button, {

     output$selected <- renderPrint(input$letters)

shinyApp(ui = ui, server = server)