Vlad
Vlad

Reputation: 3774

shinydashboardPlus: Opening a closed boxPlus

How can I open (using code) a closed boxPlus?

https://cran.r-project.org/web/packages/shinydashboardPlus/vignettes/improved-boxes.html

Upvotes: 3

Views: 627

Answers (1)

Paweł Chabros
Paweł Chabros

Reputation: 2409

I've been looking for answer for the same question and I've figured out how to do this with shinyjs.

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

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    boxPlus(
      id = "openable-box-plus",
      title = "Openable boxPlus",
      closable = TRUE
    ),
    actionButton(
      inputId = "open-box-plus",
      label = "Open boxPlus"
    )
  )
)

server <- function(input, output) {
  observeEvent(
    input$`open-box-plus`,
    runjs('
      document
        .querySelector("#openable-box-plus")
        .parentElement
        .style.display = "block";
    ')
  )
}

shinyApp(ui, server)

When you check HTML of the boxPlus before and after closing it, you can see that style display: none; is added to the <div> with class="box".

enter image description here

To select specific boxPlus I added id = "openable-box-plus". Since id went to the child div of div with display style, you have to select parent element, and change display to "block":

document
  .querySelector("#openable-box-plus")
  .parentElement
  .style.display = "block";

Upvotes: 1

Related Questions