Failing with Dynamic regions and an array of values

I seem to always have issues when trying to incorporate dynamic regions into dashboards. I am hoping someone can point out what I am doing wrong; I am sure it is stupid simple. In essence I have 2 drop downs with a list of applications (will eventually have more, probably 6-10). What I am after is to remove an item from the array when a user selects it in one drop down. So if they select Email in the first (or second, or third) drop down, it does not show up as an option in any of the others. Here is a simple reproducer:

New-UDDashboard -Title 'Home' -Content {
    $aApps = @(
        "Select",
        "Email",
        "Spreadsheets (Excel, Google Sheets, etc.)",
        "Web Page or Application",
        "PDF",
        "Locally Installed Application",
        "API",
        "Database (Oracle, SQL, etc.)"
    )

    New-UDDynamic -Id "dynSource1" -Content { 
        New-UDSelect -Id "cmbDataSource1" -Label "Data Source 1" -FullWidth -DefaultValue "Select" -Option {
            foreach ($app in $aApps) {
                New-UDSelectOption -Name $app -Value $app
            }
        } -OnChange {
            $selection = (Get-UDElement -Id "cmbDataSource1").Value
                
            $aApps = $aApps | ? {$_ -ne $selection}
            foreach ($element in $aApps) {
                Show-UDToast -Message $element -Duration 3000
            }
            Sync-UDElement -Id "cmbDataSource2"
        }
    }

    New-UDSelect -Id "cmbDataSource2" -Label "Data Source 2" -FullWidth -DefaultValue "Select" -Option {
        foreach ($app in $aApps) {
            New-UDSelectOption -Name $app -Value $app
        }
    }
}

I am running through the applications and outputting to a UDToast, and can confirm it is removing the item. However, the second drop down does not seem to update. I also tried instantiating a new array with the one element removed, rather than reusing the $aApps, but no joy there. Any suggestions would be most appreciated.

Product: PowerShell Universal
Version: 3.3.5

You should put the variable in the $Session: scope. Also, you need to reverse what select is in a dynamic region.

New-UDDashboard -Title 'Home' -Content {
    $Session:aApps = @(
        "Select",
        "Email",
        "Spreadsheets (Excel, Google Sheets, etc.)",
        "Web Page or Application",
        "PDF",
        "Locally Installed Application",
        "API",
        "Database (Oracle, SQL, etc.)"
    )
    
    
    New-UDSelect -Id "cmbDataSource1" -Label "Data Source 1" -FullWidth -DefaultValue "Select" -Option {
        foreach ($app in $Session:aApps) {
            New-UDSelectOption -Name $app -Value $app
        }
    } -OnChange {
        $Session:aApps = $Session:aApps | ? { $_ -ne $EventData }
        Show-UDToast ($Session:aApps | ConvertTo-Json) -Duration 5000
        Sync-UDElement -Id "dynSource2"
    }
    
    New-UDDynamic -Id "dynSource2" -Content { 
        New-UDSelect -Id "cmbDataSource2" -Label "Data Source 2" -FullWidth -DefaultValue "Select" -Option {
            foreach ($app in $Session:aApps) {
                New-UDSelectOption -Name $app -Value $app
            }
        }
    }
}

The code below will get you 2 UDSelect boxes that sync with each other and doesn’t remove the variables from the list (the code above will eventually erase all options).

New-UDDashboard -Title 'Home' -Content {
    $Session:SelectData = [hashtable]@{
        ds1 = ""
        ds2 = ""
    }

    $Session:Options = @(
        "Email",
        "Spreadsheets (Excel, Google Sheets, etc.)",
        "Web Page or Application",
        "PDF",
        "Locally Installed Application",
        "API",
        "Database (Oracle, SQL, etc.)"
    )
    $Session:aApps = $session:Options
    New-UDDynamic -Id "dynSource1" -Content {
        $Params = @{
            ID = "cmbDataSource1"
            Label = "Data Source 1"
            FullWidth = $true
            Option = {
                foreach ($app in $Session:aApps) {
                    New-UDSelectOption -Name $app -Value $app
                }
            }
            OnChange = {
                $Session:SelectData["ds1"] = $EventData
                If ($t = $Session:SelectData.values | Where-Object { $_ -ne "" } ) { $Exclude = $t -join '|' }
                $Session:aApps = $Session:Options | ? { $_ -notmatch $Exclude }
                Sync-UDElement -Id "dynSource2"
            }
        }
        If (-not [string]::IsNullOrEmpty( $Session:SelectData["ds1"] )) {
            $Params.Add("DefaultValue",$Session:SelectData["ds1"])
        }
        New-UDSelect @Params
    }
    
    New-UDDynamic -Id "dynSource2" -Content { 
        $Params = @{
            ID = "cmbDataSource2"
            Label = "Data Source 2"
            FullWidth = $true
            Option = {
                foreach ($app in $Session:aApps) {
                    New-UDSelectOption -Name $app -Value $app
                }
            }
            OnChange = {
                $Session:SelectData["ds2"] = $EventData
                If ($t = $Session:SelectData.values | Where-Object { $_ -ne "" } ) { $Exclude = $t -join '|' }
                $Session:aApps = $Session:Options | ? { $_ -notmatch $Exclude }
                Sync-UDElement -Id "dynSource1"
            }
        }
        If (-not [string]::IsNullOrEmpty( $Session:SelectData["ds2"] )) {
            $Params.Add("DefaultValue",$Session:SelectData["ds2"])
        }
        New-UDSelect @Params
    }
}

Thanks, I will give this a try