我正在对闪亮的仪表板进行最后的修饰。仪表板使用 googleAuthR 通过 google oauth 进行身份验证。一切正常...但我目前必须将登录按钮放在仪表板侧栏或仪表板主体中,而且我真的很喜欢将其放在仪表板标题中下拉菜单的位置。不幸的是,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
)
您可以在标题中放置任何内容,但它必须是li
类别标签dropdown
。请参见以下示例:
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)
![enter image description here](https://i.stack.imgur.com/ikTjg.gif)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)