如何在闪亮的UI输入中访问choiceNames?

时间:2017-11-05 11:51:48

标签: r shiny

我是一个带有单选按钮UI的有光泽的应用程序。这些按钮是一个命名向量。 input$radioInputs返回选择值。我如何访问这些名称,即获得输出Your choice is a and value 1

library(shiny)

ui <- fluidPage(
  sidebarPanel(
    radioButtons(inputId = "radioInputs",
                 label = "Choose radio inputs",
                 choiceNames = letters[1:3],
                 choiceValues = 1:3,
                 # choiceNames and choiceValues can be replaced with
                 # choices = c("a"=1, "b"=2, "c"=3)
                 selected = "a")  ),
  mainPanel(
    textOutput("outputText")
  )
)

server <- function(input, output) {
  output$outputText <- renderText({
    paste("Your choice is", input$radioInputs)
  }

  )
}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:0)

通过这个替换outputext可以解决问题:

  output$outputText <- renderText({
    paste("Your choice is", 
        letters[as.numeric(input$radioInputs)],
        "and the value",
        input$radioInputs)
  }

此外,selected = 1中的radioButtons正确初始化值:)