gpt4 book ai didi

r - Shinydashboard dashboardHeader 中的登录按钮

转载 作者:行者123 更新时间:2023-12-01 16:43:38 26 4
gpt4 key购买 nike

我正在对一个 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类(class)标签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

关于r - Shinydashboard dashboardHeader 中的登录按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46231234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com