簡體   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