闪亮的 selectInput 从下拉列表中选择所有内容 [英] Shiny selectInput to select all from dropdown

查看:33
本文介绍了闪亮的 selectInput 从下拉列表中选择所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的 selectInput 下拉菜单:

I have selectInput dropdown like this:

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

我想要实现的是默认情况下使 selectInput 不按任何内容过滤,就像选择全部"时一样,它应该列出所有观察结果(例如来自加利福尼亚州、科罗拉多州等)所以我试图做的是为此创建简单的逻辑:

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 已经具有 Select All 功能代码>

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)

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆