I use R / shinydasboard to create a web application that I place behind the login screen.
I'm having problems getting the main body for rendering on the sidebar menu tabs.
I tried to ensure that one of the tabs selected = TRUEstill didn't help.
Sample code below:
require(shiny)
require(shinydashboard)
Logged <- FALSE;
LoginPass <- 0;
login <- box(title = "Login",textInput("userName", "Username (user)"),
passwordInput("passwd", "Password (test)"),
br(),actionButton("Login", "Log in"))
loginfail <- box(title = "Login",textInput("userName", "Username"),
passwordInput("passwd", "Password"),
p("Username or password incorrect"),
br(),actionButton("Login", "Log in"))
mainbody <- div(tabItems(
tabItem(tabName = "t_item1", box(title = "Item 1 information")),
tabItem(tabName = "t_item2", box(title = "Item 2 information")),
tabItem(tabName = "t_item3", box(title = "Item 3 information"))
)
)
header <- dashboardHeader(title = "dashboard header")
sidebar <- dashboardSidebar(uiOutput("sidebarpanel"))
body <- dashboardBody(uiOutput("body"))
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output, session) {
USER <<- reactiveValues(Logged = Logged, LoginPass = LoginPass)
observe({
if (USER$Logged == FALSE) {
if (!is.null(input$Login)) {
if (input$Login > 0) {
username <- isolate(input$userName)
password <- isolate(input$passwd)
if (username == "user" & password == "test") {
USER$Logged <<- TRUE
USER$LoginPass <<- 1
}
USER$LoginPass <<- -1
}
}
}
})
output$sidebarpanel <- renderUI({
if (USER$Logged == TRUE) {
div(
sidebarMenu(
menuItem("Item 1", tabName = "t_item1", icon = icon("line-chart"), selected = TRUE),
menuItem("Item 2", tabName = "t_item2", icon = icon("users")),
menuItem("item 3", tabName = "t_item3", icon = icon("dollar"))
)
)}
})
output$body <- renderUI({
if (USER$Logged == TRUE) {
mainbody
}
else {
if(USER$LoginPass >= 0) {
login
}
else {
loginfail
}
}
})
}
shinyApp(ui, server)
Any suggestions on how to get the main one to show one of the tabs at boot will be greatly appreciated. I have a suspicion that this may be due to the order of loading sidebarand body, however, I'm not sure how to explore further.
I also tried conditionalPanel, but could not get this to work.
UPDATE
, .

. 