我在selectInput中有一个命名选择槽,并希望检索与选择关联的名称,而不是值. MWE: shinyApp( ui = fluidPage( sidebarPanel( selectInput("foo", label = "Select choice here:", choices = c("Choice 1" = "Choice1", "Choice
MWE:
shinyApp( ui = fluidPage( sidebarPanel( selectInput("foo", label = "Select choice here:", choices = c("Choice 1" = "Choice1", "Choice 2" = "Choice2", "Choice 3" = "Choice3"), selected = "Choice1", multiple = TRUE), textOutput("nameOfChoice") ), mainPanel()), server = function(input, output) { output$nameOfChoice = renderText(input$foo[1]) } )
哪个产生:
相反,我希望文本输出读取选择1.我该怎么做?
将您的选择放在global.R中的对象中,然后在server.R和ui.R中使用它.在global.R:
fooChoices<-c("Choice 1" = "Choice1", "Choice 2" = "Choice2", "Choice 3" = "Choice3")
在ui.R:
selectInput("foo", label = "Select choice here:", choices = fooChoices)
在server.R中:
output$nameOfChoice = renderText(names(fooChoices[fooChoices==input$foo]))