【问题标题】:shinydashboard toggle box - hide by defaultshinydashboard 切换框 - 默认隐藏
【发布时间】:2020-10-08 15:04:05
【问题描述】:

这是对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)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您可以将它包裹在另一个 div 上并使用来自 shinyjshidden 函数

    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)
    

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 2018-05-07
      • 1970-01-01
      • 2020-06-30
      相关资源
      最近更新 更多