Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collapsible 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 is

enter image description here

In the above image the collpasible box is not getting collapsed when clicked on mininize button.

I have added the addtional AdminLTE.css and shinydashboard.css file in working directory, but still problem persists.

like image 767
Vasim Avatar asked Nov 14 '16 08:11

Vasim


People also ask

How do I create boxes in shiny UI?

A basic box can be created with the box () function, and the contents of the box can be (most) any Shiny UI content. In a typical dashboard, these boxes would be placed inside a fluidRow () (we’ll see more on dashboard layout later): Boxes can have titles and header bar colors with the title and status options.

How to use collapsible box in shiny dashboard?

To use a collapsible box within shiny only. We need to add the required javascript. Just after adding css we add this file as well. includeCSS (path = "AdminLTE.css"), #added includeCSS (path = "shinydashboard.css"), #added #add this file and collapsible nature should work. includeScript (path = "app.js"), # Show activity on this post.

How to hide the text on collapse button in shiny?

To hide the text on collapse, Shiny needs to know that the sidebar is collapsed. To do so, we will add a Shiny Input that will respond to a click on the collapse button. ‘.sidebar-toggle’ is the button class.Hence,if the button is clicked, a random number is generated and assigned to input$SideBar_col_react.

What are collapse panels in shiny?

Collapse panels allow you to reduce clutter in your Shiny app by making panels of information that open and close with a user's click. Any type of content can go in a collapse panel. Standard Bootstrap styling options are available.


2 Answers

To use a collapsible box within shiny only. We need to add the required javascript. Just after adding css we add this file as well.

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

  #add this file and collapsible nature should work.
  includeScript(path = "app.js"), # 
like image 190
Vasim Avatar answered Sep 25 '22 14:09

Vasim


If you don't have a restriction to use shinydashboard, just create a dash board page without the header and the sidebar. It will enable all the features of shinydashboard and it will looks like a basic shiny app. In the code below the box collapse/uncollapse when you click on 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)
like image 23
Geovany Avatar answered Sep 21 '22 14:09

Geovany