R Shiny - 如何在selectInput中显示选择标签

时间:2018-01-05 02:44:54

标签: r shiny

我定义了一个selectInput,如下所示。我想访问每个选项的标签,并在主面板上呈现它。

如果用户选择“Sugar sweetened bev。”,我想在主面板上呈现如下内容:

“你选择了Sugar sweetened bev。”但是我得到了“你选择了ssb”。

我以这种方式设置selectInput选项的原因是因为我想要左侧作为图表的标题,而右侧是变量名称。

非常感谢任何建议或替代方向!

 library(shiny)
 ui <- fluidPage(
 sidebarLayout(
  sidebarPanel(
     selectInput("foodvars", "Select food:",
                 choices = c("Beef/Pork" = "beefpork",
                             "Sugar sweeteened bev." = "ssb",
                             "Total fruit" = "total_fruit"))),
  mainPanel(
     textOutput("dispText")))
)
ui <- fluidPage(
 sidebarLayout(
  sidebarPanel(
     selectInput("foodvars", "Select food:",
                 choices = c("Beef/Pork" = "beefpork",
                             "Sugar sweeteened bev." = "ssb",
                             "Total fruit" = "total_fruit"))),
  mainPanel(
     textOutput("dispText")))
)
server <- function(input, output) {

output$dispText <- renderText({
 paste("You chose ",input$foodvars)})
}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:3)

我们全局创建相同的命名向量,然后在逻辑Dim ArrList As Object Dim str As String Set ArrList = CreateObject("System.Collections.ArrayList") ArrList.Add ("message") Set str = ArrList.get(0) 'how to extract the message value 上使用names检索名称

vector

-output

enter image description here