10

Is it possible to place some items in the horizontal bar next to the dashboardHeader? I know you can place notificationItem on the far right like in this example. But I would like to use the same options as in dashboardSidebar like adding filters etc. I want such a filter on top: enter image description here

Tim_Utrecht
  • 1,459
  • 6
  • 24
  • 44

2 Answers2

6

Hi You can do something like this:

library(shiny)
library(shinydashboard)

CustomHeader <- dashboardHeader()
CustomHeader$children[[3]]$children <-  div(style="min-width:200px;",tags$input(id="searchbox",placeholder = "  Search...",type="text",class="chooser-input-search",style="width:200px;height:50px;"))

ui <- dashboardPage(
  CustomHeader,
  dashboardSidebar(),
  dashboardBody()
)
server <- function(input, output, session) {}
shinyApp(ui, server)

enter image description here

Pork Chop
  • 28,528
  • 5
  • 63
  • 77
  • Thanks, your example works but on my app I work with an ui.r and server. I get the following error message: ``Error in tagAssert(sidebar, type = "aside", class = "main-sidebar") : Expected tag to be of type aside`` – Tim_Utrecht Nov 03 '16 at 09:20
  • As you didnt produce an example I made one, if you can post some of the code (so it is reproducible) I can work with that – Pork Chop Nov 03 '16 at 09:21
  • I'm so stupid. I forgot to remove the original ``dashboardHeader()``.... Now your example works, thanks. But I'm actually after getting filters like ``selectInput()`` and ``numericInput`` or other shiny functions.. And I see that this just contains a searchbox. – Tim_Utrecht Nov 03 '16 at 09:35
  • 2
    It is not recommended to post `rm(list = ls())` within your code sample... – HubertL Nov 08 '16 at 19:01
  • Why isn't recommended? This way the code is fully reproducible – Pork Chop Nov 08 '16 at 19:37
  • 1
    User might loose unsaved data, at least comment it – HubertL Nov 08 '16 at 19:47
  • You're the first who complained about this. I will keep that in mind going forward thx – Pork Chop Nov 08 '16 at 19:52
  • 1
    Then I'm the 2nd to complain. Please remove the `rm(list = ls())`. For now I comment it, but better to eliminate it. – dww Nov 09 '16 at 05:35
4

Based on Pork Chop answer, you can simply use selectInput (or other shiny inputs) that you put in a div with float:left to span horizontally:

CustomHeader <- dashboardHeader()
CustomHeader$children[[3]]$children <- list(
  div(style="float:left;height:50px",selectInput("select1", NULL, c("a","b","c"))),
  div(style="float:left;height:50px",selectInput("select2", NULL, c("d","e","f"))))

ui <- dashboardPage(
  CustomHeader,
  dashboardSidebar(),
  dashboardBody(textOutput("text1"),textOutput("text2"))
)

server <- function(input, output, session) {
  output$text1 <- renderText({input$select1})
  output$text2 <- renderText({input$select2})
}

shinyApp(ui, server)
HubertL
  • 19,246
  • 3
  • 32
  • 51