【问题标题】:Using conditionalpanel in shiny where input is a vector在输入是向量的闪亮中使用条件面板
【发布时间】:2018-12-10 15:52:23
【问题描述】:

我有许多输入,我想过滤数据源。但是,我有 100 多个要渲染的输入,但我希望在任何一个时间点都只会使用少数几个。

我不想全部呈现它们以防万一,因为这会使页面混乱且难以导航。我希望制作所有小部件,并在显示之前使用条件面板检查它是否出现在列表中。

我遇到的问题是,在 %in% 运算符看来,在条件面板中的条件参数中,它没有给我一个错误 - 它只是不起作用。

我在下面做了一个轻量级的例子:

# libs ----
library(shiny)
library(shinydashboard)

# header ----
header <- dashboardHeader(title = "Example")

#sidebar ----
sidebar <- dashboardSidebar(disable = T)

#body ----
body <- dashboardBody(

  fluidRow(
    column(
      width = 12,
      selectInput(
        inputId = "control", 
        label = "choose something:",
        choices = c("a", 
                    "b", 
                    "c", 
                    "d", 
                    "e"),
        multiple = TRUE
      )
    )
  ),

  conditionalPanel(
    condition = "'a' %in% input.control",
    textInput(inputId = "bla", label = "aaaaa")
  ),

  conditionalPanel(
    condition = "'b' %in% input.control",
    textInput(inputId = "ble", label = "bbbbb")
  )

)

# all ui ----
ui <- dashboardPage(
  header = header, 
  sidebar = sidebar, 
  body = body
)

# server ----
server = shinyServer(function(input, output) {


})


# Run the application 
shinyApp(ui = ui, server = server)

我一直无法找到解决此问题的方法,感谢任何帮助!

谢谢

编辑——已解决 条件是一个 JS 表达式(感谢@edavidaja 的提醒),当我尝试使用时: condition = 'input.control.includes("a")' 失败了。 所以和我的一个 JS 开发同事一起制定了一个解决方案,并得到了解决方案...... condition = 'input.control &amp;&amp; input.control.indexOf("a") &gt; -1'

【问题讨论】:

    标签: shiny shinydashboard


    【解决方案1】:

    来自帮助:

    condition   
    A JavaScript expression that will be evaluated repeatedly to determine whether the 
    panel should be displayed.
    

    %in 是一个 R 表达式,而不是 JavaScript 表达式,所以你可能需要像 includes 这样的东西。

    此外,如果您有数百个可能不需要的内容要渲染,请考虑改用renderUI()/uiOutput()

    【讨论】:

    • 感谢您的帮助!认为我将不得不尝试renderUI / uiOutput - 我尝试使用input.control.includes(),但它似乎也不起作用。
    • 这是为了让我知道这是一个 JS 表达式 - 我得到了以下条件的解决方案。 condition = 'input.control &amp;&amp; input.control.indexOf("a") &gt; -1'
    猜你喜欢
    • 1970-01-01
    • 2017-05-19
    • 2017-04-29
    • 2014-03-03
    • 2016-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多