gpt4 book ai didi

R Shiny : Using a Vector for Display and another Vector for Value in Choice List

转载 作者:行者123 更新时间:2023-12-02 20:01:58 27 4
gpt4 key购买 nike

我很好奇是否有一种方法可以在选择列表中使用一个向量作为显示值,另一个向量作为实际值或名称,而不必显式声明每个值。

这是一个简单的例子:

 # vect1 is the vector I would like as the display list
vect1 <- c("A", "B", "C", "D", "E")

# vect2 is the vector I would like as the name group

vect2 <- c("01", "02", "03", "04", "05")


# To get the desired output, this is how I would create a selectInput widget on the
# ui side to get the desired outcome.
selectInput("exampleinput",
choices = list("A" = "01",
"B" = "02",
"C" = "03",
"D" = "04",
"E" = "05"))


# Instead, I would like to do something like the following to create the same output:
selectInput("exampleinput", choices = list(vect1 = vect2))

我不确定这是否可能,但它会非常方便和干净。该应用程序是我有不同状态的代码,这对应用程序的用户来说毫无意义。对我来说,代码是加载数据所必需的。我实际使用的向量是动态创建的。我的应用程序工作得很好,我知道我可以轻松编写一个函数来将我想要显示的状态缩写转换为我将在幕后使用的状态代码;如果像上面这样的事情是可能的,那就会更加干净和容易。

预先感谢您提供的所有帮助!

最佳答案

您可以像这样使用setNames:

choices = setNames(vect2,vect1)
selectInput("exampleinput","exampleinput", choices = choices)

关于R Shiny : Using a Vector for Display and another Vector for Value in Choice List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39169612/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com