1

因为,我的原始数据集非常庞大,所以我使用 iris 数据集重新创建了我的问题。我添加了一列“new_var”,其中包含鲜花的描述。我遇到的问题是当我从下拉菜单中选择多个输入(> 3)时,侧边栏的长度没有得到调整以显示下拉菜单中的剩余值。

我曾尝试增加侧边栏的长度,但它不起作用。我尝试用流体页面包装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)
4

1 回答 1

3

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

围绕所有仪表板元素的“包装器”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)
于 2016-07-31T20:13:12.370 回答