Below code creates 10 boxes with the ability to close each box and the ids of boxes start with 'box'.

library(shiny)
library(shinydashboardPlus)

box_create <- function(i){
  shinydashboardPlus::box(tags$p(paste0("Box",i)), 
                          id = paste0("box", i), 
                          closable = 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 am trying to show an alert to the user when he/she closes all boxes.

I noticed shiny changes the style property whenever we close one box as display = 'none'.

So is it possible to extract all styles associated with the ids which start with 'box' and check if all the style property sets as 'none' using jQuery? If for all ids style="display: none" then an alert would pop up.

I would approach it this sort of way using the built in ability to get feedback if elements are visible.

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

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

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
     uiOutput("boxes_ui")
  )
)

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

  all_boxes  <- reactive(purrr::map(1:3, ~box_create(.x)))
  
  output$boxes_ui <- renderUI({
    req(all_boxes())
  })
  
  observe({
    req(all_boxes())
    res <- purrr::map(1:3,~input[[paste0("box",.x)]]$visible)
    res2 <- as.logical(Filter(function(x)!is.null(x),res))
    
      cat("res2 : ", res2,"\n")
      if(length(res2)==0)
        return(NULL)
      
    if(!any(res2))
      showNotification("all closed", type = "warning", duration = 5)
  })
}

shinyApp(ui, server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.