0
votes

I am having a problem with this code

 output$body <- renderUI({

if(USER$Logged==TRUE)
{uiOutput("test_UI")}

if (USER$Logged == FALSE) {
box(title = "Login",textInput("userName", "Username"),
    passwordInput("passwd", "Password"),
    br(),
    actionButton("Login", "Log in"))
 }})
  output$test_UI <- renderUI ({

 tabItems(
  tabItem(tabName = "me","Hello"),
  tabItem(tabName = "Req", uiOutput("emp1")),
  tabItem(tabName = "Cand", uiOutput("emp2")),
  tabItem(tabName = "Candcomp",uiOutput("emp3")))
 })

if I remove both the if conditions in body renderUI it works fine:

      output$body <- renderUI({


uiOutput("test_UI")

  }})
    output$test_UI <- renderUI ({

 tabItems(
  tabItem(tabName = "me","Hello"),
  tabItem(tabName = "Req", uiOutput("emp1")),
  tabItem(tabName = "Cand", uiOutput("emp2")),
  tabItem(tabName = "Candcomp",uiOutput("emp3")))
 })

Why does this happen pls clarify! Thanks in advance!

1
have you tried using a conditionalPanel ? - Michael Bird
No. But if you know how to make it work here itself it will be of great help! - Apoorva Srivastava
Thanks for the help Michael Bird! Turns out conditional Panel helped me figure out my if else problem. - Apoorva Srivastava

1 Answers

1
votes
 output$body <- renderUI({

if(USER$Logged==TRUE)
{uiOutput("test_UI")}

else {
box(title = "Login",textInput("userName", "Username"),
passwordInput("passwd", "Password"),
br(),
actionButton("Login", "Log in"))
}})
output$test_UI <- renderUI ({

 tabItems(
 tabItem(tabName = "me","Hello"),
 tabItem(tabName = "Req", uiOutput("emp1")),
 tabItem(tabName = "Cand", uiOutput("emp2")),
 tabItem(tabName = "Candcomp",uiOutput("emp3")))
  }  )

It works fine with if and else simply.