如何从R中获取闪亮的selectizeInput控件的所选项目的标签?
在下面的例子中,如果用户点击DM Ask,我想检索值DM Ask,而不是DM_ask
output$group_quote_type_holder <- renderUI({
quote_type_names <- c("Bid Price", "Ask Price", "DM Bid","DM Ask")
quote_type_sql <- c("price_bid","price_ask","DM_bid","DM_ask")
names(quote_type_sql) <- quote_type_names
quote_type_named_list <- quote_type_sql
selectizeInput("group_quote_type",
label = "Select a type:",
choices = quote_type_named_list,
selected = "DM_ask")
})# end renderUI
答案 0 :(得分:0)
如果choices
中selectizeInput
的值是命名列表,则会向用户显示名称,并在服务器中返回相应的值。
如果您想显示“DM Ask”并返回“DM Ask”,只需使用您的矢量quote_type_names
,例如:
selectizeInput(
inputId = "group_quote_type",
label = "Select a type:",
choices = c("Bid Price", "Ask Price", "DM Bid", "DM Ask"),
selected = "DM Ask"
)
修改强>
抱歉,我不明白。我假设quote_type_named_list
不在globaenv中退出,它只是在renderUI
中定义,所以这样的东西?
library("shiny")
ui <- fluidPage(
uiOutput(outputId = "group_quote_type_holder"),
verbatimTextOutput(outputId = "res")
)
server <- function(input, output) {
quote_type_named_reac <- reactiveValues(x = NULL)
output$group_quote_type_holder <- renderUI({
quote_type_names <- c("Bid Price", "Ask Price", "DM Bid","DM Ask")
quote_type_sql <- c("price_bid","price_ask","DM_bid","DM_ask")
names(quote_type_sql) <- quote_type_names
quote_type_named_list <- quote_type_sql
quote_type_named_reac$x <- quote_type_named_list
selectizeInput(inputId = "group_quote_type",
label = "Select a type:",
choices = quote_type_named_list,
selected = "DM_ask")
})
output$res <- renderPrint({
names(which(quote_type_named_reac$x == input$group_quote_type))
})
}
shinyApp(ui = ui, server = server)