rshinyselectinput

Removing an item from an UpdateSelectInput


Is it possible to remove one item from $race_ethnicity array below. The choices argument returns Asian, African-American, American Indian, Filipino, Hispanic, Pacific Islander, White, and Not Reported.

Is there a way of removing Not Reported from the first code option, or is the only solution to list out the other 7 choices as in the second code option?

raw_df_filter <- raw_df
      updateSelectInput(inputId = "race",
                        choices = c(not_sel, unique(sort(raw_df_filter$race_ethnicity))))


raw_df_filter <- raw_df
      updateSelectInput(inputId = "race",
                        choices = c(not_sel, "Asian", "African-American", "American Indian", "Filipino", "Hispanic", "Pacific Islander", "White"))))

Solution

  • raw_df_filter <- raw_df
    
    # Filter out "Not Reported" from the choices
    filtered_choices <- setdiff(unique(raw_df_filter$race_ethnicity), "Not Reported")
    
    # Update the select input with the filtered choices
    updateSelectInput(inputId = "race",
                      choices = c(not_sel, filtered_choices))