这是对a previous thread的跟进。答案提供了一个默认情况下显示该框的选项,但是如何更改为默认隐藏呢? 下面的代码混合了两个答案。
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)
答案 0 :(得分:1)
您可以将其包装在另一个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)