简体   繁体   English

闪亮的仪表板页面锁定仪表板标题在顶部

[英]Shiny Dashboadpage lock dashboardHeader on top

I use R Shiny Dashboardpage to build my interactive dashboard.我使用 R Shiny Dashboardpage 来构建我的交互式仪表板。 I want to lock the dashboardHeader and sidebarMenu so that when scrolling, the header and sidebar remain on the same position.我想锁定dashboardHeader和sidebarMenu,以便在滚动时,标题和侧边栏保持在同一位置。

For the sidebarMenu, this can be done in the CSS:对于 sidebarMenu,这可以在 CSS 中完成:

.skin-blue .main-sidebar {
  position: fixed; 
  overflow: visible;
}

However, when you try the same trick for the dashboardHeader, it fails.但是,当您对dashboardHeader 尝试相同的技巧时,它失败了。 It places the dropdownMenus (the notification icons) on the left, instead of on the top right corner.它将下拉菜单(通知图标)放在左侧,而不是右上角。

How can I fix the header without changing the design of my Shiny application?如何在不更改 Shiny 应用程序设计的情况下修复标题?

Minimal working example:最小工作示例:

app.R:应用程序R:

## app.R ##
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic dashboard",
    dropdownMenu(type = "messages",
      messageItem(
        from = "Sales Dept",
        message = "Sales are steady this month."
      )
    )
  ),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
      menuItem("Widgets", tabName = "widgets", icon = icon("th"))
    )
  ),
  dashboardBody(
    ## Add some CSS shit to change colors, width, etc.
    tags$head(
      tags$link(rel = "stylesheet", type = "text/css", href = "custom.css")
    ),
    fluidRow(
      box(plotOutput("plot1", height = 2500))
    )
  )
)

server <- function(input, output) {
  histdata <- rnorm(500)

  output$plot1 <- renderPlot({
    data <- histdata[1:50]
    hist(data)
  })
}

shinyApp(ui, server)

www/custom.css: www/custom.css:

/* logo */
.skin-blue .main-header .logo {
  position: fixed; 
  overflow: visible;
}

/* navbar (rest of the header) */
.skin-blue .main-header .navbar {
  position: fixed; 
  overflow: visible;
}        

/* main sidebar */
.skin-blue .main-sidebar {
  position: fixed; 
  overflow: visible;
}

AdminLte (the framework used by shinydashboard ) had a fixed layout (see here ), you can activate it in your app by putting this line somewhere in your UI : AdminLte(由所使用的框架shinydashboard )有固定的布局(见这里),你可以把你的UI此行某处激活它在你的应用程序:

tags$script(HTML("$('body').addClass('fixed');"))

(in dashboardBody for example) (例如在dashboardBody中)

Note : This will apply a fixed layout to the header AND the sidebar.注意:这将对标题和侧边栏应用固定布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM