r - shinydashboard 切换框 - 默认隐藏
问题描述
这是对上一个线程的跟进。答案提供了一个默认显示该框的选项,但是如何将其更改为默认隐藏?下面的代码混合了两个答案。
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
useShinyjs()
),
mainPanel(
box(id = "myBox", title = "Tree Output", width = '800px',
selectInput(inputId = "myInput", label = "my input", choices = c(letters))
),
actionButton(inputId = "button", label = "show / hide")
)
)
)
server <- function(input, output){
## observe the button being pressed
observeEvent(input$button, {
shinyjs::toggle("myBox")
})
}
shinyApp(ui, server)
解决方案
您可以将它包裹在另一个周围div
并使用hidden
来自shinyjs
library(shiny)
library(shinydashboard)
library(shinyjs)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
useShinyjs()
),
mainPanel(
hidden(
div(id = "mybox_wrapper",
box(id = "myBox", title = "Tree Output", width = '800px',
selectInput(inputId = "myInput", label = "my input", choices = c(letters))
)
)),
actionButton(inputId = "button", label = "show / hide")
)
)
)
server <- function(input, output){
## observe the button being pressed
observeEvent(input$button, {
shinyjs::toggle("mybox_wrapper")
})
}
shinyApp(ui, server)
推荐阅读
- java - 获取 Mockito 异常:检查的异常对此方法无效
- actions-on-google - 触发 Google Home 设备说话
- python - LIhgtbgm 在二元目标下产生非二元预测?
- azure-sql-database - Azure 数据库中可以拥有的行数的推荐做法
- asp.net-core - 在线发布 .net core 2.2 应用并进行配置
- r - 如何创建一个组合来自 tibble 的元素的列表?
- c# - 如何编写一种方法而不是多种方法来获取用户输入并将值分配给正确的变量?
- dart - Cloud Shell 环境:创建自定义映像无法通过 SSH
- angular - 如何在没有哈希(#)路由的情况下刷新 Angular 8 的 SPA 时删除 404 错误?
- python - 如何解决线性回归中的“异常:数据必须是一维的”?