Is it possible to have multiple conditions when using conditionpanel in aa r shiny app? I want to hide a particular UI component for a couple of tabs. Below is what I am trying but it doesn't seem to be applying when I have multiple conditions:
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)
As @RyanMorton said, the problem was that you used an OR when you should have used an AND:
condition = "input.tab !== '2' || input.tab !== '3'"
is TRUE when the tab isn't 2 or isn't 3, which is always. By changing it to:
condition = "input.tab !== '2' & input.tab !== '3'"
changing the tab to 2 or 3 is enough to make the statment FALSE and hide the tab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With