Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda