【问题标题】:How to use multiple numbers in SelectInput in Shiny如何在 Shiny 的 SelectInput 中使用多个数字
【发布时间】:2018-10-22 09:42:44
【问题描述】:

我对 Shiny 和 SelectInput 函数有疑问。这是我现在的选择输入:

 selectInput("top1", label = h3("TOP500"),
                     c("TRUE" = 1,
                       "FALSE" = 0,
                       "BOTH" = 0|1), selected = 0)

我将它用于以下功能:

filter(sales_category_id == input$top1)

这是一个被 dplyr 变异的表,最后我想在 sales_category_id 0,1 或两者之间进行选择。

有人可以帮帮我吗?这不起作用,我尝试的一切都没有给我正确的结果。

顺便提一下第一个问题,所以如果我写的东西不清楚,请告诉我:)

编辑:

由于 id 只能是 0 或 1,我以这种方式修复它:

selectInput("top1", label = h3("TOP500"),
                     c("TRUE" = 0,
                       "FALSE" = 1,
                       "BOTH" = 2), selected = 0)

filter(sales_category_id != input$top1

不过,我仍然对答案很感兴趣。

【问题讨论】:

  • 选择输入可能不是解决此问题的最佳方法。你考虑过组复选框输入吗?
  • 我确实考虑过,但我仍然不相信 selectinput 是不可能的。

标签: r filter datatable shiny dplyr


【解决方案1】:
                        selectInput("top1", label = h5("TOP500"),
                     c("TRUE" = 1,
                       "FALSE" = 0,
                       "BOTH" = "BOTH"), selected = "BOTH") 

    filter(if (input$top1 == 1) sales_category_id %in% 1 
           else if (input$top1 == 0) sales_category_id %in% 0 
           else sales_category_id %in% c(0:100)) %>%

这是我最后最好的解决方案:)

【讨论】:

    猜你喜欢
    • 2017-06-10
    • 2018-07-24
    • 1970-01-01
    • 2019-02-13
    • 2020-03-21
    • 2019-01-11
    • 2019-12-19
    • 2019-12-21
    • 1970-01-01
    相关资源
    最近更新 更多