繁体   English   中英

停止 ShinydashboardPlus 中的右侧边栏隐藏应用程序的主体

[英]Stop the right sidebar in shinydashboardPlus from hiding the body of the app

是否可以阻止shinydashboardPlus的右侧边栏隐藏应用程序主体的一部分?

常规左侧边栏面板的默认行为是不隐藏应用程序主体的任何部分。 例如,在下面的左侧边栏被点击,图向右移动(你可以看到图的所有部分)。

在此处输入图片说明

单击右侧边栏面板时,不会发生此行为(请参见下面的屏幕截图)。

单击侧边栏,绘图部分被面板隐藏。 我怎样才能停止这种行为并使它一旦点击,情节就会向左移动/重新缩放以适应身体,这样我就不会隐藏部分情节?

在此处输入图片说明

示例代码

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
data(iris)

header <- dashboardHeaderPlus(
  enable_rightsidebar = TRUE,
  rightSidebarIcon = "filter"
)

sidebar <- dashboardSidebar(selectInput(inputId = "slect",
                                        label = "Selection Menu", 
                                        selected = "a",
                                        choices = LETTERS[1:3])
)

body <- dashboardBody(fluidPage(plotOutput( "scatter", 
                                  height = "700px", 
                                  width = "700px")))

rightsidebar <- rightSidebar()

ui <- dashboardPagePlus(header, 
                        sidebar, 
                        body, 
                        rightsidebar)

server <- function(input, output) {
    output$scatter <- renderPlot({
    plot(iris$Petal.Length, iris$Petal.Width, pch=21)
      cats <- levels(iris$Species)
      cols <- c("red", "blue", "yellow2")
      ind <- lapply(cats, function(z) which(iris$Species == z))
      for (i in seq(cats)) {
        points(iris$Petal.Length[ind[[i]]], iris$Petal.Width[ind[[i]]], 
               pch = 19, col = cols[i])
      }
    })
}

shinyApp(ui, server)

会话信息:

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] shinydashboardPlus_0.7.5 shinydashboard_0.7.1     shinyWidgets_0.5.3       dendextend_1.13.4       
 [5] tidyr_1.1.0              patchwork_1.0.1          ggplot2_3.3.1            shinyhelper_0.3.2       
 [9] colorspace_1.4-1         colourpicker_1.0         shinythemes_1.1.2        DT_0.13                 
[13] shiny_1.4.0.2            dplyr_1.0.0              MSnbase_2.14.2           ProtGenerics_1.20.0     
[17] S4Vectors_0.26.1         mzR_2.22.0               Rcpp_1.0.4.6             Biobase_2.48.0          
[21] BiocGenerics_0.34.0 

第一个问题是,如果您希望plotOutput调整大小,则该plotOutput不应具有 700px 的固定宽度。

第二个问题是,单击右侧边栏不会触发shinydashboard左侧边栏的调整大小事件(与此处相同)。 我通过 JS 修复了它:

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
data(iris)

header <- dashboardHeaderPlus(enable_rightsidebar = TRUE,
                              rightSidebarIcon = "filter")

sidebar <- dashboardSidebar(
  selectInput(
    inputId = "slect",
    label = "Selection Menu",
    selected = "a",
    choices = LETTERS[1:3]
  )
)

body <- dashboardBody(
  tags$script('
      $(".navbar-custom-menu").on("click",function(){
        $(window).trigger("resize");
      })'
  ),
  fluidPage(
    plotOutput(
      "scatter",
      height = "700px",
      width = "100%"
    )
  ))

rightsidebar <- rightSidebar()

ui <- dashboardPagePlus(header,
                        sidebar,
                        body,
                        rightsidebar)

server <- function(input, output) {
  output$scatter <- renderPlot({
    plot(iris$Petal.Length, iris$Petal.Width, pch = 21)
    cats <- levels(iris$Species)
    cols <- c("red", "blue", "yellow2")
    ind <- lapply(cats, function(z)
      which(iris$Species == z))
    for (i in seq(cats)) {
      points(iris$Petal.Length[ind[[i]]],
             iris$Petal.Width[ind[[i]]],
             pch = 19,
             col = cols[i])
    }
  })
}

shinyApp(ui, server)

结果

暂无
暂无

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

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