r - shinydashboardPlus:打开一个封闭的盒子Plus
问题描述
如何打开(使用代码)封闭的 boxPlus?
https://cran.r-project.org/web/packages/shinydashboardPlus/vignettes/improved-boxes.html
解决方案
我一直在寻找相同问题的答案,并且我已经想出了如何使用 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 的 HTML 时,您可以看到样式display: none;
被添加到<div>
with 中class="box"
。
要选择特定的boxPlus
,我添加了id = "openable-box-plus"
. 由于id
去了div
with div
style的子display
元素,你必须选择父元素,并更改display
为"block"
:
document
.querySelector("#openable-box-plus")
.parentElement
.style.display = "block";
推荐阅读
- flutter - 颤振 | 如何将 ThemeData 中的 fontFamily 应用到 AppBar 和 FAB
- python-3.x - 画中画 | 警告:无法生成分发要求 -ertifi 2019.11.28
- android - 如何防止android时间选择器输入无效值
- android - 带有 setIsStrongBoxBacked 的 AES 密钥 - 解密失败
- css - 过渡持续时间不适用于引导按钮
- angular - 如何以正确的方式在 Angular 8 中重新加载页面
- css - 在本机反应中将 TouchableOpacity 与 flexbox 对齐
- angular - 角材料垫扩展面板动画不起作用
- javascript - 使用 substr 制作句子计数器时遇到问题
- regex - 正则表达式 - 在两个表达式之间提取字符串,只获取最后一个外观