Reputation: 88
I've tried to generalize a problem with a viz I'm building below, which is that I need to dynamically populate the selectInput box with values from a data frame that will change over time.
I've managed to get my selectInput box to show the correct values, however when I try to show the selected value I'm getting the entire "colour" = "colour" 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)
Upvotes: 0
Views: 92
Reputation: 4100
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)
Upvotes: 1