如何将公司徽标添加到ShinyDashboard标题(不是mainPanel或mainHeader)

时间:2016-03-12 18:58:15

标签: css shinydashboard

我试着参考下面的答案但是徽标位于主面板内但不是标题面板......任何解决方案?

HeaderLogo

我看到DISTRIBUTIONS OF RANDOM VARIABLES在主面板标题内有徽标,但无法在shinyDashboard标题中使用。以下是公司徽标标题的编码:

headerPanel(
        HTML('Distributions of Random Variables v4
            <a href="http://snap.uaf.edu" target="_blank"><img align="right" alt="SNAP Logo" src="./img/SNAP_acronym_100px.png" /></a>'
        ), "Distributions of Random Variables"
    ),

以下是我添加公司徽标的编码,source codes就在这里。有什么想法吗?

dbHeader <- dashboardHeader(title = 'Reporting Dashboard',
            dropdownMenuOutput('messageMenu'),
            dropdownMenu(type = 'notifications',
                         notificationItem(text = '5 new users today', icon('users')),
                         notificationItem(text = '12 items delivered', 
                                          icon('truck'), status = 'success'),
                         notificationItem(text = 'Server load at 86%', 
                                          icon = icon('exclamation-triangle'), 
                                          status = 'warning')),
            dropdownMenu(type = 'tasks',
                         badgeStatus = 'success',
                         taskItem(value = 90, color = 'green', 'Documentation'),
                         taskItem(value = 17, color = 'aqua', 'Project X'),
                         taskItem(value = 75, color = 'yellow', 'Server deployment'),
                         taskItem(value = 80, color = 'red', 'Overall project')))
dbHeader$children$children <- HTML("<a href='http://www.scibrokes.com' target='_blank'>
                        <img align='right' alt='Logo' src='./oda-army.jpg'/></a>")

2 个答案:

答案 0 :(得分:10)

解决方案是隐藏您的图片,以便shiny呈现它就像呈现正常的dropdownMenu项一样。

正如您可能从控制台看到的那样,dashboardHeader会抛出错误

Error in FUN(X[[i]], ...) : Expected tag to be of type li

如果您尝试插入任何自定义HTML。如果您选择li标记,它甚至会详细说明

Error in FUN(X[[i]], ...) : Expected tag to have class 'dropdown'

所以这是您的交易,将您的图片添加到li包装,内容为dropdown,您就可以了。

示例代码:

library(shinydashboard)
library(shiny)

runApp(
  shinyApp(
    ui = shinyUI(
      dashboardPage(
          dashboardHeader(title = 'Reporting Dashboard',
            tags$li(class = "dropdown",
                    tags$a(href="http://snap.uaf.edu", target="_blank", 
                           tags$img(height = "20px", alt="SNAP Logo", src="https://www.snap.uaf.edu/sites/default/files/pictures/snap_symbol_color.png")
                    )
            ),
            dropdownMenuOutput('messageMenu'),
            dropdownMenu(type = 'notifications',
                         notificationItem(text = '5 new users today', icon('users')),
                         notificationItem(text = '12 items delivered', 
                                          icon('truck'), status = 'success'),
                         notificationItem(text = 'Server load at 86%', 
                                          icon = icon('exclamation-triangle'), 
                                          status = 'warning')),
            dropdownMenu(type = 'tasks',
                         badgeStatus = 'success',
                         taskItem(value = 90, color = 'green', 'Documentation'),
                         taskItem(value = 17, color = 'aqua', 'Project X'),
                         taskItem(value = 75, color = 'yellow', 'Server deployment'),
                         taskItem(value = 80, color = 'red', 'Overall project'))
          ),

          dashboardSidebar(),
          dashboardBody()
      )
    ), 

    server = function(input, output){}

  ), launch.browser = TRUE
)

希望这有帮助!

答案 1 :(得分:0)

dashboardBody( 
    tags$img(align="right",src="http://www.pagesolutions.co.uk/wp-content/uploads/2016/03/Finalised-logo.png",height="50px"),
    tags$strong("PAGE SOLUTIONS",style="color:#0a90d3"),tags$p("CLASSIFICATION MODELING",style="color:black"),
    tags$p("Customer Classification"),
    ...
)