ShinyDashboard仪表板中的登录按钮标题 [英] Login Button in shinydashboard dashboardHeader

查看:0
本文介绍了ShinyDashboard仪表板中的登录按钮标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在给仪表板做最后的润色。仪表板使用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仪表板中的登录按钮标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆