繁体   English   中英

shinydashboardPlus() 中隐藏和查找右侧边栏的图标不起作用

[英]The icon that hides and seek right sidebar in shinydashboardPlus() is not working

在下面的shinydashboardPlus()中,我根据我使用的选项卡激活和停用右侧边栏功能。 问题是,当我在第二个选项卡中时,我无法通过单击其上方的图标来隐藏右侧边栏。

## app.R ##
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(
    
  ),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    tags$hr(),
    tabsetPanel(
      id ="tabA",
      type = "tabs",
      tabPanel("Front",icon = icon("accusoft")),
      tabPanel("Data", icon = icon("table")
      )
    )
  ),
  controlbar = dashboardControlbar()
  
)

server <- function(input, output) {
  observe({
    if (input$tabA == "Front") {
      hide(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
      removeClass(selector = "body", class = "control-sidebar-open")
    } else {
      show(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
      addClass(selector = "body", class = "control-sidebar-open")
    }
  })
}

shinyApp(ui = ui, server = server)

现在我们可以使用shinydashboardPlus::updateControlbar

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    useShinyjs(),
    tags$script(HTML("$(document).find('body > div.wrapper > header > nav > div:nth-child(4) > ul').css('display', 'none');")),
    tags$hr(),
    tabsetPanel(
      id ="tabA",
      type = "tabs",
      tabPanel("Front",icon = icon("accusoft")),
      tabPanel("Data", icon = icon("table")
      )
    )
  ),
  controlbar = dashboardControlbar(id = "dashboardControlbarID", collapsed = TRUE)
)

server <- function(input, output) {
  observeEvent(input$tabA, {
    if (input$tabA == "Front") {
      hide(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
    } else {
      show(selector = "body > div.wrapper > header > nav > div:nth-child(4) > ul")
    }
    updateControlbar("dashboardControlbarID")
  }, ignoreInit = TRUE)
}

shinyApp(ui = ui, server = server)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM