ShinydashboardPlus:打开一个封闭的盒子

时间:2019-12-10 03:04:05

标签: r shinydashboard

1 个答案:

答案 0 :(得分:0)

我一直在寻找相同问题的答案,并且已经弄清楚了如何使用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)

在关闭boxPlus之前和之后检查boxPlus的HTML时,可以看到display: none;<div>一起添加了样式class="box"

enter image description here

要选择特定的boxPlus,我添加了id = "openable-box-plus"。由于iddiv风格进入div的子display,因此您必须选择父元素,并将display更改为"block"

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