You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从UpdateSelectInput的选项中移除指定项?

解决方案

当然不用手动列出所有7个选项,直接在第一段代码的基础上对race_ethnicity的结果做过滤就能移除"Not Reported",这样既省事又能保证后续新增种族选项时自动适配。

你可以这样修改代码:

raw_df_filter <- raw_df
# 先提取去重排序后的种族选项,再排除"Not Reported"
race_options <- unique(sort(raw_df_filter$race_ethnicity))
race_options <- race_options[race_options != "Not Reported"]
updateSelectInput(inputId = "race",
                  choices = c(not_sel, race_options))

或者写成更紧凑的一行版本:

raw_df_filter <- raw_df
updateSelectInput(inputId = "race",
                  choices = c(not_sel, 
                              unique(sort(raw_df_filter$race_ethnicity))[unique(sort(raw_df_filter$race_ethnicity)) != "Not Reported"]))

原理很简单:先通过unique(sort())得到有序且无重复的种族列表,再用!= "Not Reported"筛选掉不需要的选项,最后和not_sel拼接成最终的下拉选择项。

内容的提问来源于stack exchange,提问作者Shannon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 14:47:12