2016-09-28 49 views
1

整個代碼/文件可以在這個answerShinydashboard從<a href="https://rstudio.github.io/shinydashboard/structure.html#disabling-the-header" rel="nofollow noreferrer">here</a>刪除多餘的空間時,頭部被禁用

UI.R file 
library(shiny) 
library(shinydashboard) 
shinyUI( 
    dashboardPage(
    dashboardHeader(disable = TRUE), #title=textOutput("title")), 
    dashboardSidebar(uiOutput("side")), 
    dashboardBody(
      uiOutput("page") 
    ))) 

但是可以發現,我想在我的儀表盤禁用頭,與幫助下,我成功地禁用,但隨後我的儀表板中添加了一些空白區域。 (見圖像,橙色高框)。

我該如何擺脫這個?這不僅在登錄頁面,即使登錄後問題仍然存在。 enter image description here

回答

3

我認爲這是閃亮的儀表板上缺少的功能,以自動添加到身體的標題的高度。我用JavaScript技巧解決了這個問題。該解決方案基於在創建頁面之後向body的CSS min-height屬性添加50px。另外,如果窗口大小發生更改,我還添加了一個事件偵聽器來添加50像素。

library(shiny) 
library(shinydashboard) 

server <- function(input, output) { 
} 
ui <- dashboardPage(
    dashboardHeader(disable = TRUE), 
    dashboardSidebar(), 
    dashboardBody(
    tags$script('window.onload = function() { 
     function fixBodyHeight() { 
     var el = $(document.getElementsByClassName("content-wrapper")[0]); 
     var h = el.height(); 
     el.css("min-height", h + 50 + "px"); 
     }; 
     window.addEventListener("resize", fixBodyHeight); 
     fixBodyHeight(); 
    };') 
) 
) 

shinyApp(ui, server) 
+0

謝謝,但一旦我再次登錄它恢復到舊狀態。此外,側欄面板不會在標題的位置向上移動。非常感謝! – Vasim

+0

可以添加到您的問題一個最小的可重現的問題的例子? – Geovany

+0

[這裏](http://stackoverflow.com/questions/33814656/different-pages-in-shiny-app)回答,是我用過的確切代碼 – Vasim

0

您可以添加類,然後從服務器端刪除

(隱藏頭的想法得到here

library(shiny) 
library(shinyjs) 
library(shinydashboard) 
server=shinyServer(
    function(input, output,session) { 
    observeEvent(input$activate,{ 
     js$hidehead('') # show head 
     removeClass("body_d","DISABLED") # remove class 
    }) 
    }) 


ui= 
shinyUI( 
    dashboardPage(
    dashboardHeader(disable = T), #title=textOutput("title")), 
    dashboardSidebar(uiOutput("side")), 
    dashboardBody(class="DISABLED",id="body_d", 
        useShinyjs(), 
        extendShinyjs(text = "shinyjs.hidehead = function(parm){ 
            $('header').css('display', parm); 
           }"), 
     tags$style(".DISABLED { min-height: 100vh !important}; 
       "), 
     actionButton("activate","activate header") 
    ))) 

shinyApp(ui,server) 

如果你不想要的東西后,顯示頭 - 你需要添加類,並添加css min-height: 100vh !important作爲示例

相關問題