Foldable box in Shiny app

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)

This result

enter image description here

In the above image, the merge window does not shrink when the mini-button is pressed.

I added additional file AdminLTE.cssand shinydashboard.cssthe working directory, but the problem still persists.

+4
source share
2 answers

If you have no usage restrictions shinydashboard, just create a dashboard page without a title and sidebar. It will allow you to use all the features shinydashboard, and it will look like a basic brilliant application. In the code below, the window breaks / maximizes when you click the minimize / maximize button.

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)
0

. javascript. css .

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

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

Source: https://habr.com/ru/post/1660659/


All Articles