闪亮仪表盘中的动态车身 [英] dynamic body in shiny dashboard
本文介绍了闪亮仪表盘中的动态车身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用R/shinydasboard创建一个Web应用程序,并将其放在登录屏幕后面。
我在根据侧栏菜单选项卡呈现正文时遇到问题。
我已尝试确保其中一个选项卡项selected = TRUE
仍然无效。
示例代码如下:
require(shiny)
require(shinydashboard)
Logged <- FALSE;
LoginPass <- 0; #0: not attempted, -1: failed, 1: passed
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)
#Id.username <- which(my_username == Username)
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)
任何有关如何让主体在加载时显示其中一个选项卡的建议都将不胜感激。我怀疑可能是由于sidebar
和body
的加载顺序,但我不确定如何进一步调查。
我也尝试了conditionalPanel
,但也无法正常工作。
推荐答案
您需要将tabItem
设置为活动:
tabItem(tabName = "t_item1", class = "active", box(title = "Item 1 information"))
当您登录后动态呈现内容时,将呈现第一个页签。
这篇关于闪亮仪表盘中的动态车身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文