【问题标题】:dynamic select input in R shinyR闪亮中的动态选择输入
【发布时间】:2016-11-21 04:20:18
【问题描述】:

我正在尝试使用独特的功能来创建 selectInput 选项。但是,我的数据如下所示,这需要多个映射。例如,类似:

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

但不确定什么是正确的语法。

> 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))))

【问题讨论】:

  • 您的问题真的是关于闪亮还是文本操作(如何使不同的标点符号解析为同一件事)?
  • @C8H10N4O2 感谢您的调查。我认为问题在于两者,因为我不确定在 Shiny 中传递多个标点符号的正确语法是什么。 choices = c(Pro Forma` = c('Pro-forma', 'ProForma', 'Proforma', 'Pro-Forma')) 这种方式不起作用,因为它仍然在下拉菜单中创建了 4 个不同的选项,但是我只需要一个,所有四种类型的数据都会被选中。

标签: r shiny


【解决方案1】:

我认为您的问题是您的数据集未标准化。如果您有一堆非标准状态代码,例如:

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

我会将它们标准化为大小写和标点符号:

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 

从干净的数据开始可以避免以后需要变通方法。

【讨论】:

    猜你喜欢
    • 2019-06-14
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 2016-12-25
    • 2014-10-25
    • 2016-03-16
    • 2020-07-04
    相关资源
    最近更新 更多