首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ShinyDashboardPlus中左边框完全塌陷

ShinyDashboardPlus中左边框完全塌陷
EN

Stack Overflow用户
提问于 2018-11-27 20:19:26
回答 2查看 1.9K关注 0票数 6

ShinyDashboardPlus具有左侧边栏菜单折叠但仍然显示图标的功能。问题是,它不隐藏放置在侧栏中的任何按钮或输入选择。

我正在寻找以下两个解决方案之一:

1)完全像普通shinydashboard那样折叠侧边栏(隐藏按钮和输入)

2)保持左侧菜单的折叠状态,并在部分折叠时隐藏这些特性。

下面是我展示问题的代码:

代码语言:javascript
复制
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

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

sidebar <- dashboardSidebar(
  sidebarMenu(id = "menuChoice",
              menuItem("Tab 1", tabName = "Tab1", icon = icon("globe"))
  ),
  actionButton("Test", "Download", icon = icon("download")),
  selectInput(inputId = "TestChoice",label = "Selection", selected="Choice1",
              choices = c("Choice1","Choice2","Choice3"))
)

body <- dashboardBody()

rightsidebar <- rightSidebar()

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

server <- function(input, output) {}

shinyApp(ui, server)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-11-28 11:02:35

我添加了一些jquery和css代码,以模拟关闭侧栏(解决方案1)时shinydashboard的正常行为。

代码语言:javascript
复制
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

jscode <- HTML("
$(document).on('shiny:connected', function(event) {
  $('.sidebar-toggle').on('click', function() {
    if ($('body')[0].className != 'skin-blue sidebar-mini sidebar-collapse') {
      $('#sidebarCollapsed').css('display', 'none')
    } else {
      $('#sidebarCollapsed').css('display', 'block')
    }
  })
});
")

csscode <- HTML("
.sidebar-mini.sidebar-collapse .content-wrapper {
      margin-left: 0px !important;
}")

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

sidebar <- dashboardSidebar(collapsed = T,
  tags$head(tags$script(jscode)),
  tags$head(tags$style(csscode)),
  sidebarMenu(id = "menuChoice",
              menuItem("Tab 1", tabName = "Tab1", icon = icon("globe"))
  ),
  actionButton("Test", "Download", icon = icon("download")),
  selectInput(inputId = "TestChoice",label = "Selection", selected="Choice1",
              choices = c("Choice1","Choice2","Choice3"))
)
body <- dashboardBody()
rightsidebar <- rightSidebar()

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

###########################/server.R/###############################
server <- function(input, output) {}

#Combines Dasboard and Data together----
shinyApp(ui, server)

使用一些css,您可以实现解决方案2,尽管您可能必须向您的首选项添加或调整一些css:

代码语言:javascript
复制
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

csscode <- HTML("
.sidebar-mini.sidebar-collapse .shiny-bound-input.action-button {
  margin: 6px 6px 6px 3px;
  max-width: 85%;
}
.sidebar-mini.sidebar-collapse .fa {
  font-size: initial;
}
.sidebar-mini.sidebar-collapse .btn-default {
  font-size: 0;
}
.sidebar-mini.sidebar-collapse #tohide {
  display: none;
}
")

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

sidebar <- dashboardSidebar(collapsed = T,
                            tags$head(tags$style(csscode)),
                            sidebarMenu(id = "menuChoice",
                                        menuItem("Tab 1", tabName = "Tab1", icon = icon("globe"))
                            ),
                            actionButton("Test", "Download", icon = icon("download")),
                            div(id="tohide", 
                              selectInput(inputId = "TestChoice",label = "Selection", selected="Choice1",
                                          choices = c("Choice1","Choice2","Choice3"))
                                )
)

body <- dashboardBody()

rightsidebar <- rightSidebar()

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

server <- function(input, output) {}

shinyApp(ui, server)
票数 3
EN

Stack Overflow用户

发布于 2020-09-24 08:33:34

正如前面提到的这里,您可以使用shinydashboardPlus::dashboardPagePlus()函数的sidebar_fullCollapse = TRUE参数,例如:

代码语言:javascript
复制
shinyApp(
  ui = dashboardPagePlus(
    header               = dashboardHeaderPlus(),
    sidebar              = dashboardSidebar(),
    sidebar_fullCollapse = TRUE,
    body                 = dashboardBody(),
  ),
  server = function(input, output) { }
)

这是:

  1. 完全折叠侧边栏,因此没有留下图标;
  2. 不会折叠标题中的仪表板标题。
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53507487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档