在 R Shiny 应用程序中隐藏主标题切换

2023-12-22

I am looking for a way to hide main header toggle icon as we do for side bar in R Shiny App using ShinyJS Package. Attaching the Image for the reference.enter image description here

Code

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

ui <- shinyUI(dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
useShinyjs()
)
))

server <- shinyServer(function(input, output, session) {
addClass(selector = "body", class = "sidebar-collapse") # Hide Side Bar
})

shinyApp(ui = ui, server = server)

应用程序启动时隐藏侧边栏切换的一种方法是使用JS()函数来自htmlwidgets:

library(shiny)
library(shinydashboard)
library(shinyjs)
library(htmlwidgets)

ui <- dashboardPage(
  dashboardHeader(title = "Title"),

  dashboardSidebar(
    # Remove the sidebar toggle element
    tags$script(JS("document.getElementsByClassName('sidebar-toggle')[0].style.visibility = 'hidden';"))
  ),

  dashboardBody()
)

server <- function(input, output, session) {
}

shinyApp(ui = ui, server = server)

我发现以下线程对于解决这个问题很有用:

使用操作按钮启用和禁用侧边栏切换按钮 https://stackoverflow.com/questions/49278441/to-enable-and-disable-sidebar-toggle-button-using-a-action-button/52526603#52526603

在R闪亮的页面加载时调用javascript函数 https://stackoverflow.com/questions/42433961/call-javascript-function-on-page-load-in-r-shiny/42434168#42434168

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 R Shiny 应用程序中隐藏主标题切换 的相关文章

随机推荐