【问题标题】:Collapsible box in Shiny AppShiny App中的可折叠盒子
【发布时间】:2016-11-14 08:47:34
【问题描述】:
library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

  includeCSS(path = "AdminLTE.css"), #added 
  includeCSS(path = "shinydashboard.css"), #added

   # Application title
   titlePanel("Old Faithful Geyser Data"),

   # Sidebar with a slider input for number of bins 
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),

      # Show a plot of the generated distribution
      mainPanel(
         box(plotOutput("distPlot"), solidHeader = T, collapsible = T, title = "collapsible box not collapsing", status = "primary")
      )
   )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

   output$distPlot <- renderPlot({
      # generate bins based on input$bins from ui.R
      x    <- faithful[, 2] 
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      # draw the histogram with the specified number of bins
      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

这个结果是

在上图中,单击最小化按钮时,可折叠框不会折叠。

我已在工作目录中添加了额外的AdminLTE.css 和shinydashboard.css 文件,但问题仍然存在。

【问题讨论】:

标签: css r shiny shinydashboard


【解决方案1】:

仅在闪亮内使用可折叠的盒子。我们需要添加所需的javascript。在添加 css 之后,我们也添加了 this 文件。

  includeCSS(path = "AdminLTE.css"), #added 
  includeCSS(path = "shinydashboard.css"), #added

  #add this file and collapsible nature should work.
  includeScript(path = "app.js"), # 

【讨论】:

    【解决方案2】:

    如果您没有使用shinydashboard 的限制,只需创建一个没有标题和侧边栏的仪表板页面。它将启用shinydashboard 的所有功能,并且看起来像一个基本的闪亮应用程序。当您单击最小化/最大化按钮时,在框下方的代码中折叠/取消折叠。

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(disable = TRUE),
      dashboardSidebar(disable = TRUE),
      dashboardBody(
      # Application title
      titlePanel("Old Faithful Geyser Data"),
        # Sidebar with a slider input for number of bins 
        sidebarLayout(
          sidebarPanel(
             sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
          ),
          # Show a plot of the generated distribution
          mainPanel(
             box(plotOutput("distPlot"), solidHeader = T, collapsible = T, 
                 title = "collapsible box not collapsing", status = "primary")
          )
        ) 
      )
    )
    # Define server logic required to draw a histogram
    server <- function(input, output) {
       output$distPlot <- renderPlot({
          # generate bins based on input$bins from ui.R
          x    <- faithful[, 2] 
          bins <- seq(min(x), max(x), length.out = input$bins + 1)
          # draw the histogram with the specified number of bins
          hist(x, breaks = bins, col = 'darkgray', border = 'white')
       })
    }
    
    # Run the application 
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 2021-10-18
      • 2016-03-31
      • 2021-10-27
      • 1970-01-01
      • 2017-12-17
      • 1970-01-01
      • 2021-09-23
      相关资源
      最近更新 更多