selectInput in Shiny

Published by onesixx on

https://shiny.rstudio.com/reference/shiny/1.2.0/selectInput.html
http://shiny.rstudio.com/gallery/tags/selectinput/
library(shiny)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      selectInput("selI_ex", "slider Example", choice=NULL)
    ),
    mainPanel( )
  )
)

server <- function(input, output,session) {
  #way1.1  using vector
  val <-    c("NY", "NJ", 'CT')
  #way1.2  using vector
  val <-    c("New York"="NY", "New Jersey"="NJ", 'Connecticut'='CT')

  #way2.1  using list
  val <- list("NY", "NJ", "CT")
  #way2.2  using list
  val <- list("New York"="NY", "New Jersey"="NJ", 'Connecticut'='CT')
  #way2.3  using grouping list 
  val <- list(`East Coast` = list("NY", "NJ", "CT"),
              `West Coast` = list("WA", "OR", "CA"),
              `Midwest`    = list("MN", "WI", "IA"))
  
  #way3 using data.frame
  choiceList <- data.frame(state= c("New York", "New Jersey", "Connecticut"),
                           abbr = c("NY", "NJ", "CT"))
  val        <- choiceList$abbr %>% as.list
  names(val) <- choiceList$state
  
  updateSelectInput(session, inputId = "selI_ex",
                    choices = val)
}

shinyApp(ui, server)

Categories: R-Shiny

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x