条件面板R闪亮的多个条件

时间:2018-08-30 20:06:51

标签: r shiny

在有光泽的应用程序中使用conditionpanel时是否可能有多个条件?我想为几个选项卡隐藏一个特定的UI组件。以下是我正在尝试的方法,但是在有多个条件的情况下似乎不适用:

library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(DT)

sidebar <- dashboardSidebar(
  sidebarMenu(id = "tab",
              menuItem("1", tabName = "1"),
              menuItem("2", tabName = "2"),
              menuItem("3", tabName = "3")
  )
)
body <-   ## Body content
  dashboardBody(box(width = 12,fluidRow(
    fluidRow(  column(
      width = 3,  textInput("text1", label = h5("Min"), value = "1")),
      column(
        width = 3, textInput("text2", label = h5("Max"), value = "2")),
      conditionalPanel(
        condition = "input.tab !== '2' || input.tab !== '3'" , column(
        width = 3, textInput("text3", label = h5("Max"), value = "3"))),
      column(
        width = 3, textInput("text4", label = h5("Max"), value = "4")))

  )))

ui <-   dashboardPage(dashboardHeader(title = "Scorecard"),
                      sidebar,
                      body)

# Define the server code
server <- function(input, output,session) {

  output$op <-renderDataTable({
    df_format()
  })

}

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

就像@RyanMorton所说的那样,问题在于您应该使用OR时使用了AND

condition = "input.tab !== '2' || input.tab !== '3'"
当选项卡不是2或不是3时,

TRUE,通常是。通过将其更改为:

condition = "input.tab !== '2' & input.tab !== '3'"

将标签更改为2或3就足以使语句FALSE并隐藏标签