简体   繁体   English

在 shiny 仪表板 header 部分中添加 shiny 小部件

[英]Add a shiny widget inside shiny dashboard header section

Is there a way to add a selectinput() inside shinydashboardPlus() header?有没有办法在shinydashboardPlus() header 中添加selectinput() I do not want the dropdown menu ability that is offered by shinydashboardPlus() .我不想要shinydashboardPlus()提供的下拉菜单功能。 I want something like:我想要类似的东西:

在此处输入图像描述

#app.r
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(shinydashboardPlus)

shinyApp(
  ui = dashboardPagePlus(
    header = dashboardHeaderPlus(
#selectInput("variable", "Variable:",
 #           c("Cylinders" = "cyl",
  #            "Transmission" = "am",
   #           "Gears" = "gear"))
    ),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
    ),
    rightsidebar = rightSidebar(),
    title = "DashboardPage"
  ),
  server = function(input, output) { }
)

shinydashboard is a little puritanical about the contents of the dashboardHeader. shinydashboard 对dashboardHeader 的内容有些拘谨。

There are two requirements for items to appear on the header. header 上出现的项目有两个要求。 They need to have the li tag and they need to have the dropdown class.他们需要有li标签,并且需要有dropdown class。 This normally limits you to only use the built in dropdown functions from the package.这通常会限制您仅使用 package 中的内置下拉功能。 You can simply surround any widget you want to add with these and it will be added to the header.您可以简单地用这些包围您想要添加的任何小部件,它将被添加到 header。

Example:例子:

dashboardHeader(
    tags$li(selectInput('whatever','whatever',choices = c('meh1','meh2'),
            class= 'dropdown'))

You might want to control the heights of the widgets you place though because long items cause header line to break at sidebar intersection.您可能想要控制您放置的小部件的高度,因为长项目会导致 header 线在侧边栏交叉处中断。 Default maximum height appears to be 50 px.默认最大高度似乎是 50 像素。 You can fix the issue by increasing this size through css or reducing the height of the widgets you're adding.您可以通过 css 增加此大小或降低您要添加的小部件的高度来解决此问题。

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

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