我正在给仪表板做最后的润色。仪表板使用googleAuthR通过Google OAuth进行身份验证。一切都很正常。但目前我必须将登录按钮放在仪表板边栏或仪表板Body中,我真的非常希望它位于仪表板Header中的下拉列表所在的位置。不幸的是,shinydashboard的标题似乎对标题中的内容很挑剔。有没有黑客(或不是黑客)把东西放在上面?
这里有一件事情肯定不起作用,例如:
ui = dashboardPage(
dashboardHeader(
title = "My Awesome Dashboard"
, p('Pretend this is a login button')
)
, dashboardSidebar(
p('I don't want the login here.')
)
, dashboardBody(
p('I don't want the login here either.')
)
)
server = function(input, output, session) {
}
shinyApp(
ui = ui
, server = server
)
您可以在Header中放置任何内容,但它必须是dropdown
类的li
标记。请参见以下示例:
ui = dashboardPage(
dashboardHeader(
title = "My Awesome Dashboard",
tags$li(class = "dropdown",
tags$li(class = "dropdown", textOutput("logged_user"), style = "padding-top: 15px; padding-bottom: 15px; color: #fff;"),
tags$li(class = "dropdown", actionLink("login", textOutput("logintext"))))
)
, dashboardSidebar(), dashboardBody())
server = function(input, output, session) {
logged_in <- reactiveVal(FALSE)
# switch value of logged_in variable to TRUE after login succeeded
observeEvent(input$login, {
logged_in(ifelse(logged_in(), FALSE, TRUE))
})
# show "Login" or "Logout" depending on whether logged out or in
output$logintext <- renderText({
if(logged_in()) return("Logout here.")
return("Login here")
})
# show text of logged in user
output$logged_user <- renderText({
if(logged_in()) return("User 1 is logged in.")
return("")
})
}
shinyApp(ui = ui, server = server)
上一篇:调整仪表板中整个页眉栏的高度闪亮仪表板中的页眉仪表板、页眉、高度
下一篇:在shinyDashboard中的menuSubItems之间切换shinyDashboard、menuSubItems