我正在对一个 Shiny 的仪表板进行最后的润色。仪表板使用 googleAuthR 通过 google oauth 进行身份验证。一切正常......但我目前必须将登录按钮放在dashboardSidebar或dashboardBody中,我真的很喜欢它在dashboardHeader中的下拉菜单中。不幸的是,看起来 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)
关于r - Shinydashboard dashboardHeader 中的登录按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46231234/