简体   繁体   English

R Shiny中的动态选择输入

[英]dynamic select input in R shiny

I'm trying to use unique function to create the selectInput choices. 我试图使用独特的功能来创建selectInput选项。 However, my data looks like this below, which would require multiple mappings. 但是,我的数据如下所示,这将需要多个映射。 For example,something like: 例如,类似:

choices = c(`Pro Forma` = c('Pro-forma', 'ProForma', 'Proforma', 'Pro-Forma')`)

but not sure what's the correct syntax. 但不确定什么是正确的语法。

> unique(heatmap_raw$Status)
# [1] "Active"     "Redeeming"  "Proforma"   NA           "Pro-forma"  "ProForma" 
# [7] "na"         "40act"      "40 Act"     "Pro-Forma"  "40ACT"      "UCITS"   

selectInput("select month", label = ("Select Month"),
choices = c(unique(month(heatmap_raw$period))))

I think your problem is that your dataset is not normalized. 我认为您的问题是您的数据集未标准化。 If you have a bunch of non-standard status codes like: 如果您有一堆非标准状态代码,例如:

status <- c( "Active","Redeeming","Proforma",NA,"Pro-forma","ProForma","na",
             "40act","40 Act","Pro-Forma","40ACT","UCITS")  

I would standardize them for case and punctuation: 我将它们的大小写和标点标准化:

status <- tolower(gsub("\\W","",status))
# plus, do something for the NA vs. "na" status
status[is.na(status)] <- "na" # or something else, just to achieve consistency 

Starting with clean data will avoid the need for workarounds later. 从干净的数据开始将避免以后需要变通办法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM