【问题标题】:Is it posisble to have two different inputs that can filter my DT table using shiny R?是否有可能有两个不同的输入可以使用闪亮的 R 过滤我的 DT 表?
【发布时间】:2021-09-02 06:37:28
【问题描述】:

我有一个应用程序,它允许我通过输入来查看过滤器的汽车数量。

这是我的代码。

```{r}

selectInput("input_type","Select Cylinder Size: ", c("All", mtcars$cyl))
selectInput("input_type2", "Select # of Gears: ", c("All", mtcars$gear))

mtcars2 <- reactive({
  if(input$input_type=="All")
    mtcars
  else
    subset(mtcars,cyl == input$input_type)
  })


renderDataTable(
  datatable(mtcars2())
  )  

```

虽然我有第二个输入也可以让我按齿轮过滤,但它不起作用,因为我不知道如何将它与反应函数联系起来。

有什么想法吗?

【问题讨论】:

    标签: r shiny shinydashboard shinyapps rshiny


    【解决方案1】:

    类似这样的[未经测试的代码]:

    selectInput("input_type","Select Cylinder Size: ", c("All", mtcars$cyl))
    selectInput("input_type2", "Select # of Gears: ", c("All", mtcars$gear))
    
    mtcars2 <- reactive({
      d <- mtcars
      if(input$input_type !="All")
        d <- subset(d, cyl == input$input_type)
      if(input$input_type2 !="All")
        d <- subset(d, gear == input$input_type2)
      d
      })
    
    
    renderDataTable(
      datatable(mtcars2())
      )  
    

    顺便说一句,在为输入定义选择列表时,您可能希望使用unique

    【讨论】:

    • 我要感谢你——这太棒了,太完美了。
    • 嘿,非常感谢您的回答 - 我遇到了另一个问题,想知道您是否可以帮助我。链接在这里。 @Limey stackoverflow.com/questions/68025317/…
    猜你喜欢
    • 2018-08-09
    • 1970-01-01
    • 2016-08-18
    • 2020-02-03
    • 2018-04-05
    • 2017-01-12
    • 2017-07-25
    • 2014-08-30
    • 2020-08-18
    相关资源
    最近更新 更多