Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
Set an alert when all boxes are closed or collapsed in shinydashboardPlus

I have a shinydashboard with 10 boxes, and which can be closed or collapsed. All the box id starts with "box". I was trying set an alert button when all boxes are closed or collapsed.

Below is the code of the dashboard:

library(shiny)
library(shinydashboardPlus)

box_create <- function(i){
  shinydashboardPlus::box(tags$p(paste0("Box",i)), 
                          id = paste0("box", i), 
                          closable = TRUE,
                          collapsible = TRUE)
}

all_box <- purrr::map(1:10, ~box_create(.x))

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    all_box
  )
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

I have noticed on pressing close or collapse button shiny sets the display = 'none' for that box. inspect Box1

So is it possible to extract all styles associated with the id which starts with 'box' and check if all the style property sets as 'none' using jQuery?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Using shinydashboardPlus's dev version you can access the box state via it's id (pattern: input$mybox$collapsed).

Please see this related article.

Install it via devtools::install_github("RinteRface/shinydashboardPlus")

library(shiny)
library(tools)
library(shinydashboard)
library(shinydashboardPlus)

box_ids <- paste0("box", 1:10)

box_create <- function(box_id){
  shinydashboardPlus::box(tags$p(toTitleCase(box_id)), 
                          id = box_id, 
                          closable = TRUE,
                          collapsible = TRUE)
}

all_boxes <- lapply(box_ids, box_create)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    all_boxes
  )
)

server <- function(input, output, session) {
  observe({
    if(all(sapply(box_ids, function(box_id){input[[box_id]]$collapsed}))){
      showModal(modalDialog("All boxes are collapsed!"))
    }
  })

  # observe({
  #   print(paste("Is box1 collapsed?", input$box1$collapsed))
  # })
  
}

shinyApp(ui, server)

result

about 4 years ago · Juan Pablo Isaza Denunciar

0

I thought you wanted a button when all were collapsed OR all were closed. Here is a solution for that.

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)

box_create <- function(i){
  shinydashboardPlus::box(tags$p(paste0("Box",i)), 
                          id = paste0("box", i), 
                          closable = TRUE,
                          collapsible = TRUE)
}

all_box <- purrr::map(1:10, ~box_create(.x))

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    all_box,
    div(id = "alert_button")
  )
)

server <- function(input, output, session) {
  observe({
    boxes <- paste0("box", 1:10)
    visible_status <- sapply(boxes, \(x) input[[x]]$visible)
    collapsed_status <- sapply(boxes, \(x) input[[x]]$collapsed)
    if (!any(visible_status) || all(collapsed_status)) {
      insertUI(
        selector = "#alert_button",
        ui = div(id = "added", actionButton("btn","all hidden OR all collapsed"))
      )
    } else {
      removeUI(selector = "#added")
    }
  })
  
}

shinyApp(ui, server)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda