闪亮的Dashboadpage锁定仪表板顶部

时间:2017-08-16 06:41:58

标签: css r shiny

我使用R Shiny Dashboardpage来构建我的交互式仪表板。我想锁定dashboardHeader和sidebarMenu,以便在滚动时,标题和侧边栏保持在同一位置。

对于sidebarMenu,可以在CSS中完成:

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

但是,当您对dashboardHeader尝试相同的技巧时,它会失败。它将dropdownMenus(通知图标)放在左侧,而不是右上角。

如何在不改变Shiny应用程序设计的情况下修复标题?

最小的工作示例:

app.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:

/* 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;
}

1 个答案:

答案 0 :(得分:2)

AdminLte(shinydashboard使用的框架)有一个固定的布局(请参阅here),您可以在应用中将此行放在UI中的某个位置来激活它:

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

(例如dashboardBody

注意:这会将固定布局应用于标题和侧边栏。