首页 > 解决方案 > 在可折叠侧边栏闪亮中添加滑块输入

问题描述

我想在可折叠的侧边栏中添加一个滑块。我在显示与正文中的 tabName 关联的内容时遇到了一些问题。IE。当我单击选项卡时,正文中的内容不显示。

这是代码以及当我们注释掉滑块输入时的样子。

在此处输入图像描述

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Dynamic Menu"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("hello", tabName = "helloWorld", icon = icon("calendar")#,
              #sliderInput("slide", "chose Slide", min = 5, max = 10, value = 10)
              )
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "helloWorld",
              tags$h1("hey")
      )
    )
  )
)

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



}

shinyApp(ui, server)

如果我们使用滑块输入,body 就会消失。我曾尝试使用一些 java 脚本,但我似乎无法得到我正在寻找的结果。如果我决定添加另一个 menuItem,则保留在我的侧边栏中应该是可折叠的。

在此处输入图像描述

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Dynamic Menu"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("hello", tabName = "helloWorld", icon = icon("calendar"),
              sliderInput("slide", "chose Slide", min = 5, max = 10, value = 10)
              )
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "helloWorld",
              tags$h1("hey")
      )
    )
  )
)

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



}

shinyApp(ui, server)

标签: javascriptrshinyshinydashboard

解决方案


如果你完全移除你tabItemstabItem身体会怎样?

试试这个:

dashboardBody(
    tags$h1("hey")
  )

或者您想根据menuItem选择的主体拥有多个主体?


推荐阅读