本文介绍了闪亮的selectInput从下拉菜单中全选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 selectInput 下拉列表:

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

我要实现的是默认情况下使selectInput不过滤任何内容,例如在选择全部时,它应该列出所有观测值(例如,来自加利福尼亚,科罗拉多州等) b因此,我试图为此创建一个简单的逻辑:

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?

推荐答案

很棒的 shinyWidgets 包在其 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)

这篇关于闪亮的selectInput从下拉菜单中全选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 11:58