abtassociates / eva

Eva is a HUD application to aid HMIS Leads with data analysis. It is an open-source project intended for local use by HMIS Administrators in Continuums of Care (CoCs) around the U.S. and its territories.
GNU Affero General Public License v3.0
14 stars 4 forks source link

Gender single select #552

Closed kiadso closed 3 weeks ago

kiadso commented 3 weeks ago

changing gender to single-select as discussed

kiadso commented 3 weeks ago

Thanks for catching the updatePicker! I removed multi-select-related code from there, as you suggested. The if_any() needs to stay like it is because the if_any is giving column names to check. the input$syso_gender is never 1, it's always something like "All" or "ManExclusive". It works just like the RaceEthnicity one, which is also a single-select.

alex-silverman commented 3 weeks ago

Thanks for catching the updatePicker! I removed multi-select-related code from there, as you suggested. The if_any() needs to stay like it is because the if_any is giving column names to check. the input$syso_gender is never 1, it's always something like "All" or "ManExclusive". It works just like the RaceEthnicity one, which is also a single-select.

So I think this line checks if any of the columns corresponding to the selections in input$syso_gender == 1, then include them in the dataframe: if_any(.cols = c(input$syso_gender), ~ .x == 1)

But since they can only select one gender, then this should be equivalent to: input$syso_gender == 1

So if a Client has TransgenderInclusive == 1 and WomanInclusive == 1, and the user selects "Gender expansive, including transgender" (i.e. TransgenderInclusive), then this would evaluate to: TransgenderInclusive == 1 which would resolve to True.

Is there a scenario I'm missing where the first version would correctly select the Client but the simplified version would not?

kiadso commented 3 weeks ago

@alex-silverman when I tested it with input$syso_gender == 1, it failed because it's looking directly at the input. R has to know you're asking it to look at a column name or at the literal input and there's no distinction made with input$syso_gender == 1. if_any() is like the across() but for filters, so by using the .cols argument of that function, it allows us to distinguish the actual input of "ManExclusive" from the value of the column named ManExclusive. https://www.tidyverse.org/blog/2021/02/dplyr-1-0-4-if-any/

alex-silverman commented 3 weeks ago

@kiadso - sorry, you're right that input$syso_gender == 1 won't work as-is. However, !!sym(input$syso_gender) == 1 works. This is because it first evaluates input$syso_gender, then looks for a variable with that name and checks if it's equal to 1. This means the code doesn't have to check if all those columns == 1, but rather just the column corresponding to the one the user selected in inut$syso_gender.

I see why this is less intuitive, though, since it looks like the code is checking whether input$syso_gender == 1. And I doubt it will bring us much of an efficiency gain, so I'm happy to leave as if_any.

kiadso commented 3 weeks ago

Ah no I like it! I was just using if_any for that .cols argument, but if there's a clean (if not super intuitive) way to do this, I think that's the best way. I changed it for race/eth too since those work the same way.