Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
772 views
in Technique[技术] by (71.8m points)

r - Shiny selectInput to select all from dropdown

I have selectInput dropdown like this:

selectInput("locInput", "Location", choices=c("All","New Mexico", "Colorado", "California"))

What I want to achieve is to make selectInput by default not filter by anything, as in when "All" is selected then it should list all observations (so from California, Colorado etc.) So what I tried to do is create simple logic for this:

server <- function(input, output) {
  filtered<-reactive({
    shows %>%
    filter(Length >= input$lenInput[1],
           Length <= input$lenInput[2],
           if (input$locInput != "All"){
           Location==input$locInput
    })

But this doesn't seem to work. Any ideas what can I change in order to make it work correctly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There wonderful shinyWidgets package which already has the Select All feature in its pickerInput

library(shiny)
library(shinyWidgets)

ui <- basicPage(
  sidebarPanel(
    pickerInput("locInput","Location", choices=c("New Mexico", "Colorado", "California"), options = list(`actions-box` = TRUE),multiple = T)
  )
)

server <- function(input, output) {

  observe({
    print(input$locInput)
  })

}

shinyApp (ui = ui, server = server)

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...