增加闪亮仪表板侧边栏的长度

时间:2016-07-31 17:30:21

标签: r shiny shiny-server shinydashboard shinyjs

因为,我的原始数据集非常庞大,我使用虹膜数据集重新创建了我的问题。我添加了一个专栏' new_var'有花的描述。我遇到的麻烦是当我从下拉菜单中选择多个输入(> 3)时,侧边栏的长度不会被调整以显示下拉列表中的剩余值。

我已经尝试增加侧边栏的长度,但它不起作用。我尝试用dashPage包装dashboardSidebar,它也不起作用。

我真正想要的是,如果侧边栏的长度可以动态调整,那么我可以滚动查看所有值或提供垂直滚动条。感谢

library(datasets)
library(shiny)
library(shinydashboard)
library(DT)

data(iris)
x <- c("Small flowers","Flowers (or heads) borne singly on isolated stems or arising individually from leaf axils. Not part of a larger group.", "A simple, indeterminate inflorescence consisting of stalked flowers attached to a central stem and forming a more or less elongated cluster. The stalk of a flower is termed a pedicle and pedicled flowers are implied by the term raceme when used alone in the specific sense. ", "An indeterminate inflorescence consisting of stalkless flowers attached to a central stem, generally forming a highly elongated cluster. A raceme of stalkless flowers. ", "An indeterminate inflorescence forming a convex or flat-topped cluster, essentially a contracted raceme. Typically flowers arise from a central axis on stalks (pedicles) of different lengths that bring them all to near the same height. The term is also applied to racemes of similar shape with branching pedicles. The outermost flowers generally open first. ")
iris$new_var <- rep(x, each = 30)


ui <- 
  dashboardPage(
    dashboardHeader(title = strong("DATA LOADER"),titleWidth = 240),
    dashboardSidebar(

      sidebarMenu(
        selectizeInput("newvar", "Choose type of flower:", choices = sort(unique(iris$new_var)), multiple = TRUE)

      )
    ),
    dashboardBody(
      fluidRow(
        dataTableOutput("df"),
        br()
      )))

server <- function(input, output){
  output$df <- renderDataTable(reactive({
    iris[iris$new_var %in% input$newvar, ]
  })())
}
shinyApp(ui, server)

1 个答案:

答案 0 :(得分:3)

有一种css样式定义,可以保持侧边栏的向下重叠部分不可见。您只需覆盖该定义,以便页面可滚动。

&#34;包装&#34;所有仪表板元素周围都有overflow: hidden !important,显然让它看起来更像是一个真正的仪表板,而不是一个网页。很奇怪,因为dashboardBody本身是可滚动的,这只会影响侧边栏的可见性。

我在head标签内写了样式定义。这样,在ui中放置这个定义并不重要,因为它将被附加到HTML头部。

如果这不能解决您的问题,请发表评论。

以下代码:

library(datasets)
library(shiny)
library(shinydashboard)
library(DT)

data(iris)
x <- c("Small flowers", "Flowers (or heads) borne singly on isolated stems or arising individually from leaf axils. Not part of a larger group.", "A simple, indeterminate inflorescence consisting of stalked flowers attached to a central stem and forming a more or less elongated cluster. The stalk of a flower is termed a pedicle and pedicled flowers are implied by the term raceme when used alone in the specific sense. ", "An indeterminate inflorescence consisting of stalkless flowers attached to a central stem, generally forming a highly elongated cluster. A raceme of stalkless flowers. ", "An indeterminate inflorescence forming a convex or flat-topped cluster, essentially a contracted raceme. Typically flowers arise from a central axis on stalks (pedicles) of different lengths that bring them all to near the same height. The term is also applied to racemes of similar shape with branching pedicles. The outermost flowers generally open first. ")
iris$new_var <- rep(x, each = 30)

ui <- 
  dashboardPage(
    dashboardHeader(title = strong("DATA LOADER"),titleWidth = 240),
    dashboardSidebar(
      tags$head(tags$style(".wrapper {overflow: visible !important;}")),
      sidebarMenu(
        selectizeInput("newvar", "Choose type of flower:", choices = sort(unique(iris$new_var)), multiple = TRUE)

      )
    ),
    dashboardBody(
      fluidRow(
        dataTableOutput("df"),
        br()
      )))

server <- function(input, output){
  output$df <- renderDataTable(reactive({
    iris[iris$new_var %in% input$newvar, ]
  })())
}
shinyApp(ui, server)