簡體   English   中英

閃亮的儀表板頁面鎖定儀表板標題在頂部

[英]Shiny Dashboadpage lock dashboardHeader on top

我使用 R Shiny Dashboardpage 來構建我的交互式儀表板。 我想鎖定dashboardHeader和sidebarMenu,以便在滾動時,標題和側邊欄保持在同一位置。

對於 sidebarMenu,這可以在 CSS 中完成:

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

但是,當您對dashboardHeader 嘗試相同的技巧時,它失敗了。 它將下拉菜單(通知圖標)放在左側,而不是右上角。

如何在不更改 Shiny 應用程序設計的情況下修復標題?

最小工作示例:

應用程序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;
}

AdminLte(由所使用的框架shinydashboard )有固定的布局(見這里),你可以把你的UI此行某處激活它在你的應用程序:

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

(例如在dashboardBody中)

注意:這將對標題和側邊欄應用固定布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM