我是一个带有单选按钮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)
答案 0 :(得分:0)
通过这个替换outputext
可以解决问题:
output$outputText <- renderText({
paste("Your choice is",
letters[as.numeric(input$radioInputs)],
"and the value",
input$radioInputs)
}
此外,selected = 1
中的radioButtons
正确初始化值:)