我试图用下面构建的一个问题概括一个问题,这就是我需要用一个随时间变化的数据框中的值动态填充selectInput框。
我设法让我的selectInput框显示正确的值,但是当我尝试显示所选的值时,我得到整个“颜色”=“颜色< / em>“string:
library(shiny)
colour <- data.frame(colourName = c("Blue", "Green", "Red", "Green", "Red", "Purple","Orange"))
ui <- fluidPage(
htmlOutput("selectUI"),
textOutput("selection")
)
server <- function(input, output){
output$selectUI <- renderUI({
lvl.colour <- levels(colour$colourName)
selectInput(inputId = "colourSelect",
label = "Select colour",
sapply(lvl.colour, function(x) paste0(shQuote(x)," = ",shQuote(x))))
})
output$selection <- renderText({
input$colourSelect
})
}
shinyApp(ui = ui, server = server)
答案 0 :(得分:1)
library(shinydashboard)
library(shiny)
colour <- data.frame(colourName = c("Blue", "Green", "Red", "Green", "Red", "Purple","Orange"))
ui <- fluidPage(
selectInput("SelectUI", h5("Choose a colour"),colour,colour[1]),
textOutput("selection")
)
server <- function(input, output){
output$selection <- renderText({
input$SelectUI
})
}
shinyApp(ui = ui, server = server)